A really slow docker-compose problem…

Xiaoli Shen
2 min readJan 30, 2018

Got handed over a new project, which manages multiple nginx configurations and runs unit-tests in docker using a docker-compose yaml file.

When I ran

$ docker-compose -f ./docker-compose-unittest.yml up --build --force-recreate

as instructed in the README.md trying to get the tests up and have a look, docker-compose hung for one or two minutes before the test server was up.

Hadn’t I needed to stop and restart this process for every single edit to every nginx configuration file, the waiting wouldn’t have bothered me too much. But now this just made my life as miserable as hell.

Updated everything - from docker to OSX itself - brought nothing.

Searched around google and stackoverflow, tried the --verbose flag, couldn’t understand the output (the first couple of lines are like this:

urllib3.connectionpool._make_request: http://localhost:None “GET /v1.25/events?filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Duqregionalrouter%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1” 200 None
compose.cli.verbose_proxy.proxy_callable: docker events -> <generator object _stream_helper at 0x1030c16e0>

)

Tried turning off wifi, changing network, brought nothing.

What finally solved my really slow docker-compose problem was adding this line to my /etc/hosts file:

127.0.0.1 localhost localunixsocket localunixsocket.local localunixsocket.home

It seems that docker-compose was trying to resolve localhost and co., and when it couldn’t figure out where to look, it took the effort to move the whole content back and forth while building.

The particular line of code was found in this issue for docker/for-mac:

https://github.com/docker/for-mac/issues/2499

And a rough idea of how it works was found here:

https://github.com/docker/compose/issues/3419#issuecomment-221793401

Curiously enough, once docker-compose runs fast again, deleting the magical line from my /etc/hosts file won’t slow it down again.

--

--

Xiaoli Shen

Solutions Architect at AWS with focus areas in MLOps and now-code-low-code ML. 10 yrs in tech and counting. Opinions and posts are my own.