Docker Community Forums

Share and learn in the Docker community.

How to limit or rotate Docker container logs?


I don’t seem to have any limits set on the container logs and over time run out of space.

I am running 3 containers.

CONTAINER ID   IMAGE                          
3b51b531cc4d   nuclias/nuclias_connect_web    nuclias_connect_web
417c480a20a0   nuclias/nuclias_connect_core   nuclias_connect_core
1b5885ef9127   mongo:3.6.11                   mongo

Server: Docker Engine - Community
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:15:19 2020
  OS/Arch:          linux/amd64
  Experimental:     false

docker-compose version 1.25.4, build 8d51620a
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

What are my options to limit or rotate the json logs for all of the containers ?
under /var/lib/docker/containers/…

Logging Driver: json-file

The documentation states to update daemon.json file, but i don’t have it under the directory listed below

To use the json-file driver as the default logging driver, set the log-driver and log-opts keys to appropriate values in the daemon.json file, which is located in /etc/docker/ on Linux hosts

Thank you so much!

You are on the right path. The file does not exist by default. Just create it and declare you configuration. Then make sure to restart the docker service to apply the new configuration.

Thank you meyay!

Would I need to create a daemon.json file under each container or under /etc/docker ?

Just /etc/docker/daemon.json.

Afair, It should be a general setting, applied to every container that is created after the setting was applied and the docker service restarted.

can this configuration be set to specific containers?