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.
Great post what about docker logs ?
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.
I read many blogs but found correct information about the debug docker images here. I really liked it. Keep share more 🙂