Sub topic 9
Verifying settings and troubleshooting
This chapter assumes you can run containers with docker run, edit JSON files, and read a basic Compose file. It also assumes you know the json-file driver and the max-size and max-file options from earlier chapters. Here you will check which logging settings are actually in effect and fix the usual problems.
Check what is really configured
Two settings matter. The daemon default applies to new containers. Each container also stores the configuration it was created with. Check both:
docker info --format '{{.LoggingDriver}}'
docker inspect --format '{{json .HostConfig.LogConfig}}' webThe first command prints the daemon's default driver, such as json-file. The second prints the driver and options for the container named web. For a rotated container, the output looks like this:
{"Type":"json-file","Config":{"max-file":"3","max-size":"10m"}}If Config is empty, the container has no rotation, whatever you believe you configured elsewhere.
Find where the log lives
With json-file, each container writes to a file on the host. You can ask Docker for its path:
docker inspect --format '{{.LogPath}}' webRotated files sit next to it with numeric suffixes. Listing them shows whether rotation is working.
Common problems
Settings do not apply to existing containers
Logging options are fixed when a container is created. Editing daemon.json changes only containers created afterward. Changing a Compose file has no effect until the container is recreated. To apply new settings, recreate the container:
docker compose up -d --force-recreate webFor a plain docker run container, remove it and run it again with the new options. Logs stored in the old container are lost when you remove it, so copy any you need first.
The daemon does not pick up daemon.json
The daemon reads daemon.json only at startup, so restart it after every edit. On most Linux systems that is sudo systemctl restart docker. A restart stops running containers unless live restore is enabled, so plan for that. If the daemon fails to start, the JSON is probably invalid. Check for trailing commas. Also check that option values are strings. Write "max-size": "10m", and do not write "max-file": 3.
The disk is full of logs
A single container with no rotation can fill a disk. Find large log files with:
sudo du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail -5Each directory name is a container ID, so you can match it to a container with docker ps --no-trunc. Fix the cause by recreating the container with rotation. Truncating the file frees space right away, but it does not stop the growth:
sudo truncate -s 0 "$(docker inspect --format '{{.LogPath}}' web)"Options are ignored or rejected
Not every driver accepts every option. max-size and max-file belong to json-file and local. Passing them to syslog produces an error at container start. Misspelled keys also fail. Read the error message from docker run, since it names the option.
docker logs shows nothing
docker logs reads the local copy of the output. Some drivers do not keep one, in which case the command fails or returns nothing. Confirm the driver with docker inspect. Also check that the application writes to stdout or stderr. A program that writes only to a file inside the container produces no captured logs.
The application slows down or hangs
With the default blocking delivery, a slow log destination can stall the application's writes. If the container freezes while using a remote driver, check the destination first. Then consider mode=non-blocking. It trades possible dropped messages for a responsive application.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| Logs grow without limit | No `max-size` on the container | Recreate with rotation options |
| New default has no effect | Container created before the change, or daemon not restarted | Restart the daemon, recreate the container |
| Daemon will not start | Invalid JSON or numeric option values | Validate the file, quote values |
| `docker logs` empty | Driver without local copy, or output not on stdout | Check driver and application output |
| Container stalls | Blocking delivery to a slow destination | Use non-blocking mode |
Exercise
You added max-size and max-file to /etc/docker/daemon.json and restarted Docker, but an existing container web keeps producing one huge log file. What do you check and what do you do?
Show answer
Run docker inspect --format '{{json .HostConfig.LogConfig}}' web. The Config field will be empty because the container was created before the change, and daemon defaults apply only to new containers. Recreate the container, for example with docker compose up -d --force-recreate web or by removing it and running it again, and inspect it again to confirm the options appear.