Skip to content

About the author of Daydream Drift

Tomasz Niezgoda (LinkedIn/tomaszniezgoda & GitHub/tniezg) is the author of this blog. It contains original content written with care.

Please link back to this website when referencing any of the materials.

Author:

Idling Docker Containers

Published

Oftentimes, Docker's goal is to just provide an environment for running processes in. It may be a Node container used to build a project within one process and run it in another at the same time. Having such a container constantly up and running and accepting miscellaneous commands is especially useful when the container is complicated and takes a while to start and stop. In this case, Docker still needs some command or entrypoint to execute so it doesn't stop the container right away.

Here's how to do it. The easiest way is to set the entrypoint attribute to the following value:

ENTRYPOINT [ "tail", "-f", "/dev/null" ]

It can be set in Dockerfiles, docker-compose.yml and docker run ....

A more stable approach is to use dumb-init created by Yelp. dump-init is a fool-proof solution. It properly recognizes and relays termination signals like SIGINT sent to the container by the host.

If there is a specific server to run when the container starts but other containers need to wait for it to start AND subsequently accept connections the solution is to use wait-for-it. Many web servers need a database to become available before serving requests. wait-for-it can enable this. End-to-end testing requires the web server to accept connections first before running tests. wait-for-it can ensure this too.