Reputation: 7448
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
Upvotes: 45
Views: 65503
Reputation: 11347
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.
Upvotes: 83
Reputation: 777
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
Upvotes: 20