Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify max log json file size in docker compose

I am trying to specify the max file size for json-file in docker-compose.yml, like this,

log-opt:
  max-size=50m

but when I tried to docker-compose up, it threw me an error,

ERROR: In file './docker-compose.yml', service 'log-opt' must be a mapping not a string.

How to fix it?

ps. I am using docker 1.11.2

like image 856
daiyue Avatar asked Aug 22 '16 11:08

daiyue


People also ask

How do I limit the size of a docker log?

Docker doesn't limit the size of the files or how many log files there can be for a single container. If you continue to run that container, the log file will grow as long as it has drive space to do so.

How do I change the log level in a docker container?

You can run the command kubectl exec -it <container_name> bash and use the command line inside the container to change the environment variable . You can do it by running the command export LOG_LEVEL=debug or export LOG_LEVEL=error inside the container.

How do I get full docker logs?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

How do I reduce docker logs?

As a current workaround, you can turn off the logs completely if it's not of importance to you. This can be done by starting docker daemon with --log-driver=none . If you want to disable logs only for specific containers, you can start them with --log-driver=none in the docker run command.


2 Answers

Your yaml syntax isn't quite correct. The documentation says it should be options not log-opt (https://docs.docker.com/compose/compose-file/#logging). Try this?

services:
    service_name:        
        logging:
            driver: "json-file"
            options:
                max-size: "50m"

You should define logging section in each one of your services not directly in root of docker-compose.

like image 124
Matthew Avatar answered Oct 22 '22 05:10

Matthew


max-size store log files until they reach a max-size of VALUE (eg: "2048m").

Example docker-compose file config with max-size.

version: '3.2'
services:
  logstash:
    image: docker.elastic.co/logstash/logstash:7.8.0
    command:  --config.reload.automatic  
    user: savio:savio
    restart: unless-stopped
    logging:
      driver: "json-file"
      options:
        max-size: "2048m"
    ports:
      - "9600:9600" 

If you are making a change for an already running container, you need to stop and remove the container and start again.

check log settings

]# docker container inspect -f '{{.HostConfig.LogConfig}}' <ContainerName>

For more detail: link

like image 41
Savio Mathew Avatar answered Oct 22 '22 05:10

Savio Mathew