Skip to content
Ercan Ermis
Ercan Ermis

notes for everyone about cloud technology

  • Cloud
    • AWS
    • GCP
  • Container
    • Kubernetes
    • Docker
  • Linux
  • DevOps
  • Privacy Policy
  • Contact
Ercan Ermis

notes for everyone about cloud technology

Enable Logrotation for Docker Containers

Ercan, November 29, 2019April 24, 2021

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.

Share on Social Media
x facebook linkedin reddit
DevOps Docker containerdevopsdocker

Post navigation

Previous post
Next post
  • AWS (45)
    • Serverless (4)
  • Best (9)
  • DevOps (16)
  • Docker (10)
  • GCP (3)
  • Kubernetes (3)
  • Linux (13)
  • Uncategorized (6)

Recent Posts

  • Automating AWS CloudWatch Log Group Tagging with Python and Boto3
  • Automating AWS ECR Tagging with Python and Boto3
  • Automating ECR Image Cleanup with Bash
  • Update ECR Repositories with Bash Script
  • Why Automated Tests Are Essential in Your CI/CD Pipeline and Development Flow
  • Streamline Your AWS ECR Management with This Powerful Bash Script
  • Setting up DKIM for Google Workspace (Gmail) using Terraform and AWS Route 53
  • Automate AWS Site-to-Site VPN Monitoring
  • Optimizing Docker Images: Tips for Reducing Image Size and Build Time
  • Monitoring EC2 Disk Space with a Simple Bash Script and Slack Alerts
  • Securing Docker Containers: Best Practices for Container Security
  • Mastering Dockerfile: Writing Efficient, Scalable Container Builds
  • Migrating a Git Repository from GitLab to GitHub with GPG-Signed Commits
  • Accessing AWS Services in Private Subnets Without 0.0.0.0/0
  • Understanding AWS Regions, Availability Zones, and VPCs: A Comprehensive Guide
©2025 Ercan Ermis | WordPress Theme by SuperbThemes