The cart is empty

In today's IT landscape, monitoring and logging of key operations and events are indispensable for the management and operation of containerized applications. Docker, a leading platform for containerization, offers various options for container log management. This article provides a detailed guide on setting up system logging for Docker containers using journald on the CentOS 7 operating system.

Prerequisites

Before beginning, ensure your CentOS 7 system has Docker installed and is updated to the latest available versions. This can be achieved by running the following commands:

sudo yum update
sudo yum install docker

Also, make sure the Docker service is started and enabled to automatically start at boot time:

sudo systemctl start docker
sudo systemctl enable docker

Configuring Docker to Use journald

Docker allows the configuration of the logging driver at the daemon level as well as at the individual container level. To set journald as the default logging driver for all containers, follow these steps:

  1. Editing the Docker Daemon Configuration File Edit or create the Docker daemon configuration file in /etc/docker/daemon.json and add journald as the default log driver:

    {
      "log-driver": "journald"
    }
    

    If the /etc/docker/daemon.json file already exists, ensure you are only adding or modifying the log-driver key.

  2. Restarting the Docker Daemon To apply the changes, the Docker daemon needs to be restarted:
    sudo systemctl restart docker
    ​

 

Viewing Container Logs

After setting journald as the log driver, you can use the journalctl tool to view the logs of containers. An example of viewing logs for a specific container:

sudo journalctl CONTAINER_NAME=<container_name>

This command will display all logs for a specific container. You can also filter logs by time, severity level, and other criteria offered by journalctl.

By using journald as the log driver for Docker containers on CentOS 7, you can efficiently centralize and manage the logs of your containers. This method offers a robust and flexible solution for monitoring and analyzing logs, which is crucial for the maintenance and security of containerized applications.