Working with Docker logs All you need to know









Are you facing difficulties using docker logs?

This guide is for you.

Sometimes, it feels better to efficiently troubleshoot Docker container issues.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix docker related issues.
Now, we shall look into the ways to manage docker logs.

How to start working with Docker log?

What happens if you’ve run into issues with a Docker container?
The first thing is to collect the necessary information which helps to resolve the issue. This obtains from the container’s logs.
So, this is an easy way to troubleshoot your Docker containers,
It is very easy to view your container’s log file. The logs are only written for running containers. Also, it’s possible to view log files from stopped containers as well.
Now, let us see the process of working with Docker logs.

1. Collect the necessary information

In order to view a container’s logs, we must know the name of the container in question. The container ID or the image name needs to know to troubleshoot the issues.
For example, "ibmimedia" is the container name. To find out the name and ID, issue the command:

$ docker ps

In our case, let us check the names associated with ibmimedia.
The docker ps command shows those names are:

e8403ec3d16d
ibmimedia


2. Viewing the logs

Viewing the Docker logs for a container performs with the below command:

$ docker logs CONTAINER_ID

Where CONTAINER_ID is the ID of the container that want to use.
For instance, we run the following command if want to view the ibmimedia's logs;

$ docker logs e8403ec3d16d

Alternatively, if the above command does not help to troubleshoot a container, we use tail command that helps to view the log files being written as they happen.
For that, we run the following command,

$ docker logs --tail=10 -f e8403ec3d16d

At this point, tail would follow the log file and shows the last 10 lines of output.
And, this method works with all containers.
For example, a Debian container can be spun using the command given below:

$ docker run -it debian /bin/bash

On another terminal, issue the following command to check the logs:

$ docker logs --tail=10 -f 200a

Where 200a is the first four characters in the Debian container ID.

Now, we get plenty of information regarding a container.

[Need urgent assistance to start working with docker logs? We are available to help you.]

Conclusion

This article will guide you on how to start using docker logs efficiently.