37

I have a project with a dockerfile and a docker-compose.yml for deploying it. But if I run docker-compose up, the command prints Building app and hangs forever. I do not see any steps being performed. It isn't downloading images either since there's no network traffic, and the images used are available in the cache.

How can I go about debugging and fixing this issue on my machine? Is there a verbose option for docker(-compose) that I could use?

Bonifacio2
  • 2,978
  • 4
  • 33
  • 48
fctorial
  • 585
  • 1
  • 5
  • 9

5 Answers5

109

As this is the top hit for "docker-compose hangs", I'll post the solution for my problem that would have saved me 30 minutes of searching. If even docker-compose --version hangs, this might be your fix.

Docker-compose seems to hang indefinitely when the system has low entropy. You can check this by running:

cat /proc/sys/kernel/random/entropy_avail

If the output is less than 1000, that is almost certainly why it's hanging. I was experiencing this on a VPS, where the available entropy was less than 10.

The fix for me was to install haveged, which immediately increased my available entropy to over 2500, and caused docker compose to work normally.

Installation is as easy as

apt install haveged
milosmns
  • 3,188
  • 4
  • 30
  • 43
Phillip Elm
  • 1,705
  • 2
  • 17
  • 25
  • 4
    Thanks, this worked for me, but I've never had this problem before on the (virtual) machine where it happened. Why would this happen? – Will Vousden Jul 03 '21 at 14:45
  • 1
    @WillVousden my guess would be that a process on the host was draining the entropy pool faster than it could be replenished. IIRC, entropy can take a while to accumulate, especially on virtualized hardware. – Phillip Elm Jul 05 '21 at 06:24
  • 28
    Legend. I would not have guessed this in a million years. Thank you. – hraban Jul 06 '21 at 02:14
  • 2
    `[sudo] apt-get install haveged` – Tulleb Sep 09 '21 at 16:18
  • 3
    Jumped from 68 to 2238 after the install and docker-compose has been significantly more responsive since. This answer wins my vote for best of 2021 as I would have NEVER guessed this approach. – Chris Porter Dec 21 '21 at 21:08
  • 2
    you are legend. we don't upvote enough the question and the answer these days. – Calvintwr Jan 11 '22 at 11:27
  • 2
    Wow, no comment. I'd be interested in learning why this helps, but it definitely does. @everyone-at-stack-overflow don't forget to upvote!!! – milosmns Feb 06 '22 at 11:07
  • 3
    @milosmns - thanks! yeah this one came out of left field. it's been a while - but iirc, compose makes a call to libsodium that blocks until there's enough entropy - even when it doesn't really seem to need it (such as the `--version` command). It seems that in some cases, virtual private servers don't generate enough entropy to ever satisfy this condition, so the process hangs indefinitely. – Phillip Elm Feb 08 '22 at 09:50
  • 1
    I am at a loss for words. How bizarre. Thank you. – Tobias Fünke Feb 15 '22 at 07:33
22

Try to run it with this option and see if helps:

docker-compose --verbose up

*Note: If you haven't build your container, run the same command with the option --build

Felipe Malara
  • 1,601
  • 1
  • 5
  • 13
8

I ran into this problem last night, the problem for me was a large sub directory of images, 66GB. Adding the sub directory to .dockerignore file resolved the issue

gordonbanderson
  • 161
  • 1
  • 3
  • 1
    This fixed my problems with version 1.27 of docker-compose. My fix was to create a .dockerignore file to the same directory with my docker-compose.yml file and include the name of the "big" subdir in it. – Robert McLean Aug 09 '21 at 16:36
  • adding a .dockerignore file and ignoring a large directly (10+gb) also fixed it for me. thanks – Scratcha Oct 18 '21 at 13:17
2

I have recently faced that issue this is how I fixed it. There can be multiple reasons for it. But in my case it was because of RAM and memory issue this is how I fixed it

  • Increased RAM from 2 to 4GB
  • Increase Swap memory from 1 to 2GB

If you don't have any such problem, better to verbose it. That will show you the interactive logs on the console

Or you can see the logs of the container

docker logs --tail=200 bootcamp
Umar Asghar
  • 3,182
  • 1
  • 31
  • 27
0

If you are in a country like Iran probably the problem is sanction you can fix it using VPN or custom anti sanction DNS like

178.22.122.100
185.51.200.2 
OR 
185.55.225.25
185.55.226.26

or you can use unofficial docker registries built for crossing sanction limits like https://docker-registry.ir/

Mahdi mehrabi
  • 1,120
  • 1
  • 10
  • 18