Enable Logrotation for Docker Containers

Ercan (@flightlesstux)
1 min readSep 18, 2020

When you install and use Docker on your system, the container running in the docker can generate a large number of logs while you are not aware of the background.

Although the Docker service normally supports logrotate, this support comes off by default. If one day your disk ends suddenly, then you will know exactly what I mean. : )

If you are installing the docker service for the first time in a server and running the container for the first time, you can follow the steps below.

When the docker service is in a stop state, first open the file that the docker service will need for the logrotate operation with the text editor. My favorite is vim, I used vim. You can also choose another editor like nano, pico.

sudo vim /etc/docker/daemon.json

Then add the following lines in this file and save and close the file.

{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}

Now, don’t forget to restart your docker service.

sudo systemctl restart docker

Now, your docker service started to rotation logs under your “/var/lib/docker/containers/CONTAINERID/” path.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Ercan (@flightlesstux)
Ercan (@flightlesstux)

Written by Ercan (@flightlesstux)

⌨️ Solution Architect, formerly DevOps Engineer Lead 👨‍👩‍👧‍👦 3x @AWSCommunity Builder 😶‍🌫️ Certified #AWS Solution Architect (SAA-C03) 🐍 #Python Dev♥️

No responses yet

Write a response