Docker - Logging


Advertisements

Docker has logging mechanisms in place which can be used to debug issues as and when they occur. There is logging at the daemon level and at the container level. Let’s look at the different levels of logging.

Daemon Logging

At the daemon logging level, there are four levels of logging available −

  • Debug − It details all the possible information handled by the daemon process.

  • Info − It details all the errors + Information handled by the daemon process.

  • Errors − It details all the errors handled by the daemon process.

  • Fatal − It only details all the fatal errors handled by the daemon process.

Go through the following steps to learn how to enable logging.

Step 1 − First, we need to stop the docker daemon process, if it is already running. It can be done using the following command −

sudo service docker stop 

Docker Daemon Process

Step 2 − Now we need to start the docker daemon process. But this time, we need to append the –l parameter to specify the logging option. So let’s issue the following command when starting the docker daemon process.

sudo dockerd –l debug &

The following points need to be noted about the above command −

  • dockerd is the executable for the docker daemon process.

  • The –l option is used to specify the logging level. In our case, we are putting this as debug

  • & is used to come back to the command prompt after the logging has been enabled.

Points

Once you start the Docker process with logging, you will also now see the Debug Logs being sent to the console.

Debug Logs

Now, if you execute any Docker command such as docker images, the Debug information will also be sent to the console.

Docker Images Logging

Container Logging

Logging is also available at the container level. So in our example, let’s spin up an Ubuntu container first. We can do it by using the following command.

sudo docker run –it ubuntu /bin/bash 

Container Logging

Now, we can use the docker log command to see the logs of the container.

Syntax

Docker logs containerID 

Parameters

  • containerID − This is the ID of the container for which you need to see the logs.

Example

On our Docker Host, let’s issue the following command. Before that, you can issue some commands whilst in the container.

sudo docker logs 6bfb1271fcdd 

Output

Container Logging Output

From the output, you can see that the commands executed in the container are shown in the logs.

Advertisements