You must have seen issues in your docker container where it crashes or gets stopped multiple times. You need to identify the root cause of the issues and make your stopped or crashed container work again. In this post, we will learn the methods to debug a docker container

Prerequisites

Multiple steps are needed to find the actual root cause of your docker container crash. Let’s see the steps one by one

Find the docker container which is in an exited or crashed state

You first need to find the docker container which is behaving abnormally. List down all the container which is either in running or stopped. I have created some containers on my machine and we will see those containers only.

docker ps -a

The -a option lists down the stopped container also

View all docker containers

Three containers are up and running but the mysqld-exporter container is in stopped. The container ID of the MySQL Exporter container is d3253f7d5d1c. In your case, the container ID will be different.

View Docker Logs

Whenever any application has an issue, we check the logs and try to find the issues that are happening with the application. The same principle is applied to the docker container and you must see the logs first. You can view docker logs using the below command

docker logs <container-id>

Let’s see the logs of our mysqld-exporter (d3253f7d5d1c ) docker container

docker logs d3253f7d5d1c

I gave the wrong file name, dfdscfg/.my.cnf, deliberately causing the logs to show the error that no configuration was found. The correct filename should have been cfg/.my.cnf

By viewing the docker logs you should be able to identify the errors. The above logs command will put all the logs on your screen and the prompt will exit but if you want to see the continuous logs or tail the logs then you need to use the –follow option

docker logs --follow <container-id>

Inspect Docker Container

You can view the low-level details of the docker container using the inspect command. Docker inspect can give you details about

  • Network Settings
  • Graphic Driver Config
  • Volume details
  • State
  • Image details
docker inspect <container-id>

References

Leave a Reply

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