3 Tools to Debug and Troubleshoot Docker Containers


Docker is a powerful platform that allows developers to build, deploy, run, maintain and manage containers. With all this power comes some drawbacks. In fact, one of the frustrations that often surfaces while using Docker is exactly how to troubleshoot images and containers.

In this article we’ll go over a few different ways to make Docker based solutions a bit easier to debug and troubleshoot.

Photo by Neringa Hünnefeld on Unsplash

Export a Docker Container to an Archive

When to use it: If you find you need to examine the contents of a container, but you cannot run the container or should not run the container.

This process will build the image, create the container and then export the container to a tar file for analysis.

1) Build the image.

$ docker build -t “aspwithdotnet/the-new-image:0.0.1” .

2) Create the container.

$ docker create ——name the-new-container aspwithdotnet/the-new-image:0.0.1

3) Export the container to an archive.

$ docker export the-new-container > the-new-container.tar

4) Open the tar file in the GUI or the via the CLI.

Inspect a Running Docker Container

When to use it: if you need low level details on docker objects. For example, docker inspect is great at providing the size of a container, fetching a container’s IP Address, retrieving a container’s image name, et. al.

This process will inspect a running container to get the size (in bytes) of all of it’s files.

1) Run the container.

$ docker run -it ——name the-new-container aspwithdotnet/the-new-image:0.0.1

2) Inspect the container.

$ docker inspect ——size the-new-container -f ‘{{ .SizeRootFs }}’

Run a Command in a Running Container

When to use it: if you need to run a command inside a docker container.  docker exec attaches to a running container and runs the command you provide. Here, we run bash which will allow us to run many different commands within the running container.

Using docker exec to create a bash shell in the running, “the-new-container” container.

$ docker exec -it the-new-container bash

If you enjoyed this article on troubleshooting Docker containers, checkout our other articles on containers.


%d bloggers like this: