How to debug Docker images

Yaniv   September 28, 2015   3 Comments on How to debug Docker images

Sometimes it is necessary to check why the Docker image you downloaded or created has issues starting up. In order to debug it, you need to access the Docker container.

 

Debugging an Image that does not run

First run docker images to list the existing images and IDs:

docker images

Then run the command below to run and access the image:

docker run -it --rm 1ac8b9ac41e1 /bin/bash

Replace 1ac8b9ac41e1 with the correct image ID that you would like to debug.

 

Debugging an image with a preset CMD (such as Docker Composer images)

First run docker images to list the existing images and IDs:

docker images

Then run the command below to run and access the image:

docker run -it --rm --entrypoint=/bin/bash 1ac8b9ac41e1

Replace 1ac8b9ac41e1 with the correct image ID that you would like to debug.

 

Debugging a running container

First run docker images to list the currently running container and their IDs:

docker ps

Then run the command below to run and access the image:

docker exec -it 1ac8b9ac41e1 /bin/bash

Replace 1ac8b9ac41e1 with the correct image ID that you would like to debug.

 

3 thoughts on “How to debug Docker images

  1. Yaniv Post author

    Using docker logs to debug is also a good method. However, sometimes, it is required to look at the contents of files inside the docker image, which the above methods come in handy.

    Reply
  2. DevOps Consult

    I read many blogs but found correct information about the debug docker images here. I really liked it. Keep share more 🙂

    Reply

Leave a Reply to Yaniv Cancel reply

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