At the daemon logging level, there are four levels of logging available−
Go through the following steps to figure out how to enable logging.
Step 1 − First, we want to stop the docker daemon process, if it is already running. It very well may be finished using the following order −
sudo service docker stop
Step 2 − Now we really want to start the docker daemon process.But this time, we really want to attach the - l parameter to indicate the logging option. So how about we issue the following command while starting the docker daemon process.
sudo dockerd –l debug &
The following points should be noted about the above command −
When you start the Docker process with logging, you will also now see the Debug Logs being sent to the console.
Now, if you execute any Docker command such as docker images, the Debug information will also be sent to the console.
Container LoggingLogging is also available at the container level. So in our example, we should spin up a Ubuntu container first. We can do it by using the following command-
sudo docker run –it ubuntu /bin/bash
Now, we can use the docker log command to see the logs of the container.
Docker logs containerID
ExampleOn our Docker Host, we should give the following command. Before that, you can issue commands while in the container.
sudo docker logs 6bfb1271fcdd
From the output, you can see that the commands executed in the container are displayed in the logs.