Docker

How Can I Examine Failed Docker Container Logs?

Docker container logs are records of the events and messages that appear within a Docker container. They provide a detailed record of what has happened inside the container, including any error messages, warnings, or informational messages that were generated by the applications running inside the container. They can be helpful for debugging purposes or for gathering performance data.

This article will exemplify the step-by-step procedure to examine failed Docker container logs.

How to Examine Failed Docker Container Logs?

To examine the failed Docker container logs, follow the provided steps:

  • List all the Docker containers
  • Select a failed Docker container
  • View failed Docker container logs using the “docker log <container-name/ID>” command

Step 1: Select the Failed Container

First, display the available Docker containers and choose a specific container that has failed:

docker ps -a

 

The above command has displayed all the available Docker containers and we have selected the “redis-cont” container.

Step 2: Examine Container Logs

Now, examine the selected failed container log via the “docker logs <container-name>” command:

docker logs redis-cont

 

In the above output, the logs of the “redis-cont” container including the error message can be seen.

Alternatively, users can utilize the Container ID along with the “docker logs” command to view the log of the desired container:

docker logs dfea0ea813b4

 

Moreover, the “–tail” option with the “docker logs” command can also be used to restrict the number of log lines shown:

docker logs --tail=10 redis-cont

 

The above output has displayed just 10 lines of the container logs.

Conclusion

To examine the failed Docker container logs, first, list all the containers and choose a failed container. Then, run the “docker log <container-name/ID>” command to view the failed container logs. Moreover, users can use the “–tail” option with the “docker logs” command to reduce the number of log lines shown. This article has illustrated the method to examine failed Docker container logs.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.