When removing an orphans is bad…

So Docker creates containers, when you stop these containers the container still exists it is simply stopped.

And then we create more containers…and more containers…and more containers…until we look at docker ps -a and see dozens. As such I recently began using the --remove-orphan flag of docker-compose. 

As the project progressed it got to the point where we were ready to integration out micro-services. So I started up the API server, then the user frontend…and the server exited with a code 137. Hua? Checked ports: ok, checked logs: nothing, check Google / GitHub / Stack Overflow; not much stated explaining why one service would cause another to exit with a SIGTERM command.

Come to find out when you start a stack based on a docker-compose.yml docker uses the directory name as the project name. Since we try not to clutter the root of projects both/all projects have a structure of ./{app root}/docker/{service name}. Soooo --remove-orphan was removing the services not attached to the YML file of the application. Essentially termination everything not itself.

Well, I thought, we can name containers we should be able to name the project right? Nope. As of 1.13, networks, containers, and swarm can be name (iirc) in the docker-compose.yml configuration. But to name a  projects it can only be done on the CLI during container run.

:S there went 3 hours of my life under the assumption of consistency from a tool.

TL;DR: Never assume your toolset operates consistently, always verify.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.