Giter VIP home page Giter VIP logo

docker-log-cleaner's Introduction

log-cleaner

Features

  • A standalone docker container.
  • Designed to clear the log files for a docker container at specified intervals.
  • Can be used for clearing logs in multiple containers.
  • Only functional with the driver: "json-file".

Startup commands

sudo docker-compose up -d

force recreate and show logs

sudo docker-compose up -d --build --force-recreate && sudo docker-compose logs -f

Environment variables

  • CLEAN_FREQUENCY - an integer and represents seconds so 60 = 1 minute, 3600 = 1 hour
  • CONTAINERS_T0_CLEAN - the container_name of the containers to have their logs cleaned.
  • INCLUDE_SELF - whether the current container (log-cleaner by default) should also have it's logs cleaned, defaults to TRUE
  • SELF_NAME - name of the current container (defaults to log_cleaner)

Examples

The following docker-compose.yml example will clear the logs of containers with names mongo nginx every 3600 seconds (hourly)

version: '2'

services:

  log-cleaner:
    image: smoloney/docker-log-cleaner:latest
    build:
      context: .
      dockerfile: Dockerfile
    container_name: log-cleaner
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/containers/:/var/lib/docker/containers/
    environment:
      - CLEAN_FREQUENCY=3600
      - CONTAINERS_T0_CLEAN=mongo nginx
      - INCLUDE_SELF=FALSE
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
        max-file: "1"

The following docker-compose.yml example will clear the logs of containers with names mongo nginx log-cleaner every 3600 seconds (hourly)

version: '2'

services:

  log-cleaner:
    image: smoloney/docker-log-cleaner:latest
    build:
      context: .
      dockerfile: Dockerfile
    container_name: log-cleaner
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/containers/:/var/lib/docker/containers/
    environment:
      - CLEAN_FREQUENCY=3600
      - CONTAINERS_T0_CLEAN=mongo nginx
      - INCLUDE_SELF=TRUE
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
        max-file: "1"

The following docker-compose.yml example will clear the logs of containers with names mongo nginx my-logger-cleaner every 3600 seconds (hourly)

version: '2'

services:

  log-cleaner:
    image: smoloney/docker-log-cleaner:latest
    build:
      context: .
      dockerfile: Dockerfile
    container_name: my-logger-cleaner
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/containers/:/var/lib/docker/containers/
    environment:
    - CLEAN_FREQUENCY=3600
    - CONTAINERS_T0_CLEAN=mongo nginx
    - INCLUDE_SELF=TRUE
    - SELF_NAME=my-logger-cleaner
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
        max-file: "1"

Notes

  • This project is not designed as a replacement for the docker-compose logging directives but rather as an adjunct to the logging directive.
  • If this feature is implemented in docker then this project will become defunct and hopefully this will be the case. There was an issue about this in docker/compose in github.

Acknowledgement

Licence

MIT Licence

docker-log-cleaner's People

Contributors

eirenauts-infra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.