Skip to content
Advertisement

docker-compose up very slow but docker-compose run on linux very fast

As the title said. Docker-Compose is very slow while running a container. It keeps saying it’s trying to attach to… when i run “docker-compose up“. It takes about 10 minutes before the python script is running.

On the other hand.. If I start “docker-compose run docker-build” the python script runs in a second.

If i use “docker run –rm -it Name_of_docker_image” the python script also runs in a second.

Why do i need to wait 10 minutes before it start the python script with docker-compose up?

➜  stack git:(master) ✗ docker --version
Docker version 17.06.2-ce, build cec0b72
➜  stack git:(master) ✗ docker-compose --version
docker-compose version 1.16.1, build 6d1ac21

➜  stack git:(master) ✗ netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN     
tcp6       0      0 :::5355                 :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN

“docker-compose.yml:”

version: "3"
services:
  docker-build:
    build: ./
    ports:
    - "4242:5000"

“Dockerfile:”

FROM ubuntu:16.04
# Ubuntu
RUN apt-get update
COPY . /
CMD ["/usr/bin/python", "run.py"]

“run.py”

#!/usr/bin/python
import time

a = 0
while True:
    a += 1
    print("Number of seconds past > {}".format(a))
    time.sleep(1)

Thanks in advance!

edit Full log

➜  minerva_stack git:(master) ✗ docker-compose --verbose up
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.find_config_file: Trying paths: ['/home/mikelaptop/.docker/config.json', '/home/mikelaptop/.dockercfg']
docker.auth.find_config_file: No config file found
compose.cli.command.get_client: docker-compose version 1.16.1, build 6d1ac21
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
compose.cli.command.get_client: Docker base_url: http+docker://localunixsocket
compose.cli.command.get_client: Docker version: KernelVersion=4.10.0-35-generic, Arch=amd64, BuildTime=2017-09-05T19:57:44.123196188+00:00, ApiVersion=1.30, Version=17.06.2-ce, MinAPIVersion=1.12, GitCommit=cec0b72, Os=linux, GoVersion=go1.8.3
compose.cli.verbose_proxy.proxy_callable: docker info <- ()
compose.cli.verbose_proxy.proxy_callable: docker info -> {u'Architecture': u'x86_64',
 u'BridgeNfIp6tables': True,
 u'BridgeNfIptables': True,
 u'CPUSet': True,
 u'CPUShares': True,
 u'CgroupDriver': u'cgroupfs',
 u'ClusterAdvertise': u'',
 u'ClusterStore': u'',
 u'ContainerdCommit': {u'Expected': u'6e23458c129b551d5c9871e5174f6b1b7f6d1170',
                   u'ID': u'6e23458c129b551d5c9871e5174f6b1b7f6d1170'},
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- (u'minervastack_default')
compose.cli.verbose_proxy.proxy_callable: docker inspect_network -> {u'Attachable': False,
 u'ConfigFrom': {u'Network': u''},
 u'ConfigOnly': False,
 u'Containers': {},
 u'Created': u'2017-09-25T14:10:59.758868469+02:00',
 u'Driver': u'bridge',
 u'EnableIPv6': False,
 u'IPAM': {u'Config': [{u'Gateway': u'172.18.0.1',
                    u'Subnet': u'172.18.0.0/16'}],
       u'Driver': u'default',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={u'label': [u'com.docker.compose.project=minervastack', u'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={u'label': [u'com.docker.compose.project=minervastack', u'com.docker.compose.service=docker-build', u'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'a2ed9143cd91fe2513405a63c94f6e60d9f78d5b011b4e237b6e13000c6d5d3b')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'docker-default',
 u'Args': [u'run.py'],
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
         u'Env': [u'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- (u'minervastack_docker-build')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {u'Architecture': u'amd64',
 u'Author': u'',
 u'Comment': u'',
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={u'label': [u'com.docker.compose.project=minervastack', u'com.docker.compose.service=docker-build', u'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- (u'minervastack_docker-build')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {u'Architecture': u'amd64',
 u'Author': u'',
 u'Comment': u'',
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'a2ed9143cd91fe2513405a63c94f6e60d9f78d5b011b4e237b6e13000c6d5d3b')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'docker-default',
 u'Args': [u'run.py'],
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
         u'Env': [u'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
...
compose.service._containers_have_diverged: minervastack_docker-build_1 has diverged: 7780d5caeeb57c4d4b31e0170604a9127a5e560f39551d48dee0fd0e31de8b77 != 47a8bfe707f4f0d002ae10ba5058fa5167db1f6e6c2166a2a1d9580dcbfc45fb
compose.parallel.feed_queue: Pending: set([<Service: docker-build>])
compose.parallel.feed_queue: Starting producer thread for <Service: docker-build>
Recreating minervastack_docker-build_1 ... 
compose.parallel.feed_queue: Pending: set([<Container: minervastack_docker-build_1 (a2ed91)>])
compose.parallel.feed_queue: Starting producer thread for <Container: minervastack_docker-build_1 (a2ed91)>
compose.service.recreate_container: Recreating minervastack_docker-build_1
compose.cli.verbose_proxy.proxy_callable: docker stop <- (u'a2ed9143cd91fe2513405a63c94f6e60d9f78d5b011b4e237b6e13000c6d5d3b', timeout=10)
compose.cli.verbose_proxy.proxy_callable: docker stop -> None
compose.cli.verbose_proxy.proxy_callable: docker rename <- (u'a2ed9143cd91fe2513405a63c94f6e60d9f78d5b011b4e237b6e13000c6d5d3b', u'a2ed9143cd91_minervastack_docker-build_1')
compose.cli.verbose_proxy.proxy_callable: docker rename -> None
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- (u'minervastack_docker-build')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {u'Architecture': u'amd64',
 u'Author': u'',
 u'Comment': u'',
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- (u'sha256:f421c2e81f499f49254753aa3d5b91ab6fe5b8afc2573b3797bd09730bf27ef3')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {u'Architecture': u'amd64',
 u'Author': u'',
 u'Comment': u'',
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- (u'minervastack_docker-build')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {u'Architecture': u'amd64',
 u'Author': u'',
 u'Comment': u'',
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
...
compose.service.build_container_labels: Added config hash: 47a8bfe707f4f0d002ae10ba5058fa5167db1f6e6c2166a2a1d9580dcbfc45fb
compose.cli.verbose_proxy.proxy_callable: docker create_host_config <- (device_read_iops=None, mem_swappiness=None, links=[], oom_score_adj=None, cpu_count=None, pids_limit=None, cpuset_cpus=None, dns_search=None, pid_mode=None, init_path=None, log_config={'Type': u'', 'Config': {}}, cpu_quota=None, read_only=None, cpu_percent=None, device_read_bps=None, storage_opt=None, init=None, dns=None, volumes_from=[], ipc_mode=None, mem_reservation=None, security_opt=None, shm_size=None, device_write_iops=None, dns_opt=None, cgroup_parent=None, group_add=None, network_mode=u'minervastack_default', blkio_weight_device=None, userns_mode=None, tmpfs=None, nano_cpus=None, port_bindings={'5000/tcp': ['4242']}, isolation=None, memswap_limit=None, restart_policy=None, volume_driver=None, devices=None, extra_hosts=None, binds=[], sysctls=None, blkio_weight=None, device_write_bps=None, cap_add=None, mem_limit=None, cap_drop=None, privileged=False, ulimits=None, cpu_shares=None)
compose.cli.verbose_proxy.proxy_callable: docker create_host_config -> {'Binds': [],
 'Links': [],
 'LogConfig': {'Config': {}, 'Type': u''},
 'NetworkMode': u'minervastack_default',
 'PortBindings': {'5000/tcp': [{'HostIp': '', 'HostPort': '4242'}]},
 'VolumesFrom': []}
compose.cli.verbose_proxy.proxy_callable: docker create_container <- (name=u'minervastack_docker-build_1', image=u'minervastack_docker-build', labels={u'com.docker.compose.service': u'docker-build', u'com.docker.compose.project': u'minervastack', u'com.docker.compose.config-hash': '47a8bfe707f4f0d002ae10ba5058fa5167db1f6e6c2166a2a1d9580dcbfc45fb', u'com.docker.compose.version': u'1.16.1', u'com.docker.compose.oneoff': u'False', u'com.docker.compose.container-number': '1'}, host_config={'NetworkMode': u'minervastack_default', 'Links': [], 'PortBindings': {'5000/tcp': [{'HostPort': '4242', 'HostIp': ''}]}, 'Binds': [], 'LogConfig': {'Type': u'', 'Config': {}}, 'VolumesFrom': []}, environment=[], volumes={}, detach=True, ports=[(u'5000', u'tcp')], networking_config={u'EndpointsConfig': {u'minervastack_default': {u'IPAMConfig': {}, u'Aliases': ['docker-build']}}})
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.cli.verbose_proxy.proxy_callable: docker create_container -> {u'Id': u'7167233b39bc991d11cd502dd9f4bc680c5a1341a8f9fc1ff321429b3287dc18',
 u'Warnings': None}
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'7167233b39bc991d11cd502dd9f4bc680c5a1341a8f9fc1ff321429b3287dc18')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'',
 u'Args': [u'run.py'],
 u'Config': {u'ArgsEscaped': True,
         u'AttachStderr': False,
         u'AttachStdin': False,
         u'AttachStdout': False,
         u'Cmd': [u'/usr/bin/python', u'run.py'],
         u'Domainname': u'',
         u'Entrypoint': None,
         u'Env': [u'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
...
compose.cli.verbose_proxy.proxy_callable: docker attach <- (u'7167233b39bc991d11cd502dd9f4bc680c5a1341a8f9fc1ff321429b3287dc18', stderr=True, stream=True, stdout=True)
compose.cli.verbose_proxy.proxy_callable: docker attach -> <generator object frames_iter at 0x7f7552800460>
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network <- (u'7167233b39bc991d11cd502dd9f4bc680c5a1341a8f9fc1ff321429b3287dc18', u'minervastack_default')
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network -> None
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network <- (u'7167233b39bc991d11cd502dd9f4bc680c5a1341a8f9fc1ff321429b3287dc18', u'minervastack_default', ipv4_address=None, link_local_ips=None, ipv6_address=None, links=[], aliases=[u'7167233b39bc', 'docker-build'])
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network -> None
compose.cli.verbose_proxy.proxy_callable: docker start <- (u'7167233b39bc991d11cd502dd9f4bc680c5a1341a8f9fc1ff321429b3287dc18')
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.parallel.feed_queue: Pending: set([])
compose.cli.verbose_proxy.proxy_callable: docker start -> None
compose.cli.verbose_proxy.proxy_callable: docker remove_container <- (u'a2ed9143cd91fe2513405a63c94f6e60d9f78d5b011b4e237b6e13000c6d5d3b')
compose.cli.verbose_proxy.proxy_callable: docker remove_container -> None
Recreating minervastack_docker-build_1 ... done
compose.parallel.feed_queue: Pending: set([])
compose.parallel.parallel_execute_iter: Finished processing: <Service: docker-build>
compose.parallel.feed_queue: Pending: set([])
Attaching to minervastack_docker-build_1
compose.cli.verbose_proxy.proxy_callable: docker events <- (decode=True, filters={u'label': [u'com.docker.compose.project=minervastack', u'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker events -> <generator object _stream_helper at 0x7f7552800780>

Advertisement

Answer

The issue is because of buffered logs. You should either change

CMD ["/usr/bin/python", "run.py"]

to

CMD ["/usr/bin/python", "-u", "run.py"]

Or you should update your docker-compose.yml

version: "3"
services:
  docker-build:
    build: ./
    ports:
    - "4242:5000"
    environment:
      - "PYTHONUNBUFFERED=1"

PS: Taken from http://tarunlalwani.com/post/why-delayed-output-python-docker/

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement