Let’s say you have a container that’s being launched by something which reads a Docker Compose file. For some reason, this container is crashlooping when it’s launched, which makes it difficult to a) read the logs in time, and b) log in to investigagte.
There are two Compose file attributes for the service which might come in useful:
command: this will override the command specified in the Dockerfile. We need something which will not immediately terminate;
tail -f /dev/null will do nicely.
healthcheck: if the container’s Dockerfile has a healthcheck configured, it will restart when the healthcheck timeout expires. Since the container is broken, this is likely going to happen while you’re debugging, which can be annoying. Thankfully this can be disabled.
The service definition in the Compose file then looks like this:
service: foo: image: example/foo:latest # all the other usual settings command: "tail -f /dev/null" healthcheck: disable: true
Re-deploy the containers and debug in peace. Don’t forget to remove those lines when you’re done.