Enable Logrotation for Docker Containers

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.

Working as a DevOps. If you need anything, just contact me. Lover of; #linux #centos #debian #aws #gcp #terraform #automation #python #bash

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A beginner’s guide for K8s setup using Kubectl | Cloudplex

HackerRank’s 30 Days of Code: Days 0 & 1

Introduction to Delta Lake

Introducing Dominic — From heritage conservation to Scrum Master

The web is getting less accessible to people with disabilities

Blurry image of a torso in a beige jacket with his fingers gripping chain link fencing

Creating User functionality for your Rails web application

1/23 to 1/24: Spend $2 for a $10 Certificate with code: WARMUP

Create a Chatbot in Under 10 Minutes Using PubNub Functions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ercan Ermis

Ercan Ermis

Working as a DevOps. If you need anything, just contact me. Lover of; #linux #centos #debian #aws #gcp #terraform #automation #python #bash

More from Medium

How To Install ELK Stack On Windows Server 2019 With Let’s Encrypt SSL


Making yourself at home with a introduction to Command Line Interface

A “welcome to our home” sign

The idea behind Docker and Linux containers