View and rotate Docker container logs
Read, follow and filter Docker container logs, then set log rotation with max-size and max-file so container logs never fill your VPS disk again.
- Beginner
- Linux VPS
- 4 min read
Docker captures everything a container prints to standard output and standard error. That makes debugging easy, but by default Docker keeps those logs forever, and a chatty container can quietly fill the disk. This guide shows how to read logs efficiently and how to cap their size for every container on the server.
Before you start
- A Linux VPS with Docker Engine installed. See Install Docker and Docker Compose.
- A user that can run
dockercommands, andsudofor editing/etc/docker/daemon.json. - A few minutes where restarting containers is acceptable, because the rotation settings apply when containers are created.
Read logs with docker logs
Show everything a container has logged:
docker logs webThe options you will use most:
-ffollows new lines as they arrive, liketail -f. Press Ctrl + C to stop.--tail 100shows only the last 100 lines.--since 30mor--since 2026-11-09T10:00:00limits output by time.-tadds a timestamp to every line.
Combine them:
docker logs -f --tail 50 -t webdocker logs writes the container's standard error to your terminal's standard error. To search everything with grep, merge the two streams:
docker logs --since 1h web 2>&1 | grep -i errorRead logs with Docker Compose
From the folder with your compose.yaml:
docker compose logs -f --tail 50
docker compose logs -f appThe first follows every service in the project with a coloured prefix per service. The second follows only app.
Where the logs are stored
With the default json-file driver, each container's log is a file on the host:
docker inspect --format '{{.LogPath}}' webIt is usually under /var/lib/docker/containers/<id>/. Check how big these files are:
sudo du -h /var/lib/docker/containers/*/*-json.log | sort -h | tailIf one file is several gigabytes, you have found your disk problem.
Logs only exist for what the app writes to standard output and standard error. If an app writes to its own log files inside the container, docker logs will not show them, and Docker will not rotate them.
Set log rotation for all new containers
Edit the daemon configuration:
sudo nano /etc/docker/daemon.jsonIf the file is empty or missing, add:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}Each container now keeps at most three files of 10 MB. If the file already has other settings, add the two keys inside the existing braces and keep the JSON valid.
Docker also offers a local log driver, which compresses rotated files and rotates by default. It is a good choice too, but json-file with limits is the most widely supported by log tools.
Restart Docker to load the change:
Restarting Docker stops every container briefly. Containers with a restart policy of always or unless-stopped come back on their own. Do it during a quiet period.
sudo systemctl restart dockerIf Docker refuses to start, the JSON is invalid. Check it with:
sudo dockerd --validate --config-file /etc/docker/daemon.jsonApply rotation to existing containers
The new defaults apply only to containers created after the change. Existing containers keep their old settings until you recreate them. With Compose:
docker compose up -d --force-recreateYou can also set limits per service in the Compose file, which overrides the daemon defaults:
services:
app:
image: myapp:1.0
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"For a single docker run container, add --log-opt max-size=10m --log-opt max-file=3.
Free space from a huge log right now
If the disk is already full and you cannot recreate the container yet, empty its log file in place:
sudo truncate -s 0 "$(docker inspect --format '{{.LogPath}}' web)"This deletes the old log lines but keeps the container running. Do not delete the file with rm, because Docker keeps it open and the space would not be freed.
Check it works
Confirm a container has the new limits:
docker inspect --format '{{.HostConfig.LogConfig}}' webYou should see {json-file map[max-file:3 max-size:10m]}. Over the following days, the log folder for that container should never hold more than three files.
Troubleshooting
- Docker fails to start after editing daemon.json: a missing comma or quote. Run the validate command above, fix the file, then start Docker again.
- Rotation does not apply: the container was created before the change. Recreate it.
- `docker logs` shows nothing: the app logs to a file inside the container, not to standard output. Check the image docs for a setting that logs to the console.
- `docker logs` says the driver does not support reading: some drivers, such as
syslog, send logs elsewhere. Read them in the destination system, or switch back tojson-fileorlocal.
Next steps
- Browse logs in a web page: Dozzle Docker log viewer.
- Reclaim disk from images and caches: Free disk space with docker system prune.
- Want more room for logs and data? See Linux VPS plans.
Was this guide helpful?
Still stuck?
Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.
Related guides
Docker & DevOps
Self-host Jellyfin with Docker and hardware transcoding
Install Jellyfin in Docker on a Linux VPS, mount your media library, publish it over HTTPS and switch on hardware transcoding with VAAPI or Intel Quick Sync.
- Intermediate
- Linux VPS
- 6 min read
Docker & DevOps
Deploy a Self-Hosted App with Docker Compose from Scratch
Write a compose.yaml, keep your secrets in .env, start the stack with docker compose up -d, then verify it and update it later without losing data.
- Beginner
- Linux VPS
- 7 min read
Docker & DevOps
Manage secrets and environment variables in Docker Compose
Keep API keys and database passwords out of your compose file using .env files, environment keys and Docker secrets, then confirm containers read them correctly.
- Intermediate
- Linux VPS
- 7 min read