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
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With