How can the file size and number of logs be configured …

To set the size and number of log files for Docker, you can achieve this by editing Docker’s configuration file. Here are the specific steps:

Open the Docker configuration file daemon.json. On Linux, this file is typically located in the /etc/docker/ directory, and on Windows, it is usually found in the C:\ProgramData\docker\config directory. If the file does not exist, you can create it.

Edit the `daemon.json` file and add the following content in it:

{

  "log-driver": "json-file",

  "log-opts": {

    "max-size": "10m",

    "max-file": "3"

  }

}

In this example, we have configured a maximum size of 10MB per log file (“max-size”: “10m”) and set a maximum of 3 log files to be retained at a time (“max-file”: “3”). You can adjust these values as needed.

Save and close the daemon.json file.

Restart the Docker service to apply configuration changes. On Linux, you can use the following command to restart the Docker service:

sudo systemctl restart docker

On Windows, you can restart the Docker service using the following command:

Restart-Service Docker

After completing the above steps, Docker will limit the size and quantity of log files based on the configuration. New log files will be rolled over according to the specified size, and old log files exceeding the specified quantity will be deleted.

bannerAds