Member-only story
5 Simple Tips For Debugging Docker Containers
Smoke out annoying container problems with minimal insanity

Sometimes Docker containers can be a black box. Whether you built the underlying image or you’re using a public one, a flapping container is frustrating. Figuring out what is going on can be difficult due to the way containers are executed and how they handle logging.
In this article, we’ll explore a few basic commands and parameters you can use to troubleshoot particularly fussy containers. If the container fails to start, intermittently blows up or you just want more insight into the image details, these simple options are real game changers.
1. Better logging and timestamps
The first and simplest example is to use the logging tools that Docker provides already. Most people already know how to look at the logs inside a container:
docker logs <container_id>
But what if this particular container has been running for a long time and has a log the size of Texas? In cases like this, you can simply add the extra --tail
parameter:
docker logs --tail 10 <container_id>
Using the --tail
option you can see just the last n
lines of the log. Passing in the number of lines you want to see allows you to jump right to the most relevant and recent info.
If your log output from within the container doesn’t contain timestamps by default, you can add those too. Docker allows you to pass the -t
flag to log
which will prepend each line with a timestamp:
docker logs -t <container_id>
These options can also be combined to form a precise troubleshooting instrument. Now you’ll be able to tell exactly when something happened without having to alter anything inside the container.
2. Executing commands as root
If you’re using an image that runs as the default root user, then this isn’t an issue. When you do not run as root and instead use an unprivileged user, this is a great troubleshooting tool.
If you run:
docker exec -it <container_id> /bin/sh