Docker containers can fill a Linux server’s disk even when the application itself uses very little storage. One common cause is uncontrolled container log growth.
A container may continuously write messages to standard output and standard error. Docker captures these messages and stores them according to the configured logging driver. If log rotation is not configured, a busy container can generate large log files that eventually consume available disk space.
This guide explains how to identify oversized Docker logs, investigate the containers responsible, configure log rotation, and prevent recurring disk exhaustion without damaging running containers or application data.
Docker uses logging drivers to collect and store output generated by containers.
The default logging driver is json-file. It stores container output in JSON-formatted files. By default, this driver does not automatically rotate log files based on a maximum size.
This can become a problem when applications generate large amounts of output, especially when they repeatedly log:
For example, an application running inside a container might continuously generate error messages because it cannot connect to its database. Docker keeps collecting those messages, and the associated log file can continue growing.
The problem is not necessarily Docker itself. The application may be producing unnecessary output, while the logging configuration allows that output to accumulate indefinitely.
Docker explains this behavior in its official logging driver configuration documentation.
Before changing the configuration, identify whether Docker logs are actually responsible for the disk usage.
Run:
df -h This command displays filesystem capacity, used space, and available space.
To inspect inode usage as well, run:
df -i A filesystem can run out of inodes even when some storage capacity remains available.
Run:
docker system df For a more detailed breakdown, use:
docker system df -v These commands provide an overview of Docker images, containers, volumes, and build cache usage.
The usual Linux location is /var/lib/docker, but administrators can configure a different Docker data directory.
Find the actual location with:
docker info --format '{{.DockerRootDir}}' On a typical Linux installation using the default Docker data directory, run:
sudo find /var/lib/docker/containers \
-type f \
-name '*-json.log' \
-exec du -h {} + 2>/dev/null |
sort -h |
tail -15 This lists some of the largest JSON log files.
If Docker uses a different data directory, replace /var/lib/docker/containers with the corresponding containers directory under the actual Docker root.
List running containers:
docker ps Then inspect the logging configuration of a specific container:
docker inspect \
--format '{{.HostConfig.LogConfig.Type}}' \
CONTAINER_NAME To find the log file path:
docker inspect \
--format '{{.LogPath}}' \
CONTAINER_NAME Replace CONTAINER_NAME with the actual container name or ID.
These checks help identify the container and its logging configuration before any changes are made.
One of the most effective solutions is to configure log rotation.
Docker’s json-file logging driver supports two important options:
max-size: Maximum size of an individual log file before rotation.max-file: Maximum number of log files retained.For example, the following configuration limits each log file to 10 MB and retains up to three files.
On a typical Linux installation, the configuration file is:
/etc/docker/daemon.json Open it with:
sudo nano /etc/docker/daemon.json If the file already contains configuration settings, preserve them and merge the logging settings into the existing JSON object. Do not overwrite unrelated configuration.
Use:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
} The values in log-opts must be strings, including numeric-looking values such as max-file.
With this configuration, Docker rotates logs when they reach the configured size and retains up to three log files for each container using these options.
See the official Docker JSON File logging driver documentation for the supported options.
On Linux systems using systemd, apply the daemon configuration with:
sudo systemctl restart docker Important: Restarting Docker may affect running workloads depending on the host configuration. Perform this operation during an appropriate maintenance window and verify the impact on your services first.
There is another important detail: changing daemon.json does not automatically update the logging configuration of existing containers. The new defaults apply to containers created after the daemon configuration change.
Existing containers must be recreated to receive the new logging settings.
For Docker Compose projects, you can configure logging options directly in the service definition.
Add the following section under the relevant service in your compose.yaml or docker-compose.yml file:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3" For example, a service definition may look like this:
services:
web:
image: nginx:latest
ports:
- "8080:80"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3" The logging section controls the configuration for that service’s container.
After updating the Compose file, recreate the affected containers so the new settings take effect:
docker compose up -d --force-recreate Review the Compose project and its volume configuration before running this command. Recreating services can cause temporary downtime, so plan the operation appropriately.
Docker also provides a local logging driver.
For many standalone Docker installations, this is a practical alternative because it performs automatic log rotation by default and uses a more efficient storage format.
A basic daemon configuration is:
{
"log-driver": "local"
} The local driver has default rotation settings, including a maximum log size of 20 MB and up to five log files. These options can also be customized.
For example:
{
"log-driver": "local",
"log-opts": {
"max-size": "20m",
"max-file": "5"
}
} The choice of logging driver depends on the environment.
Use the local driver when local container log storage and automatic rotation meet your requirements. If your environment depends on a particular logging pipeline or driver, verify compatibility before changing it.
Read the official Docker Local File logging driver documentation.
After recreating the affected container, inspect its logging settings:
docker inspect \
--format '{{json .HostConfig.LogConfig}}' \
CONTAINER_NAME For a json-file configuration, the output should include the configured size and file count.
You can also verify the active logging driver:
docker info --format '{{.LoggingDriver}}' To review recent application messages without printing the entire log history, use:
docker logs --tail 100 CONTAINER_NAME Monitor filesystem usage again:
df -h If log growth continues, investigate the application generating the messages. Log rotation limits storage consumption, but it does not fix repeated application errors or unnecessary debugging output.
For broader Linux administration and filesystem management, see the related Linux Server Administration Guide and Linux File System Explained.
Avoid manually deleting or modifying Docker’s *-json.log files while the Docker daemon is managing them.
Docker explicitly warns that external access to these files can interfere with its logging system and produce unexpected behavior.
Configure rotation through Docker’s logging driver instead.
Updating daemon.json changes the default configuration for newly created containers. Existing containers retain their original logging configuration until they are recreated.
A container that produces thousands of repeated error messages can fill its log files quickly, even when rotation is enabled.
Inspect recent messages and investigate the underlying application problem.
Commands such as docker volume prune can remove unused volumes. Volumes may contain persistent application data, so inspect their contents and usage before removing them.
Log rotation and Docker cleanup are different operations. Do not use destructive cleanup commands as a substitute for proper logging configuration.
Docker’s default json-file logging driver does not enable log rotation by default. Containers that generate substantial output can therefore accumulate large log files.
Configure max-size and max-file in /etc/docker/daemon.json, or define logging options for individual services in Docker Compose.
No. Changing the daemon’s default logging configuration does not automatically update existing containers. Recreate the affected containers to apply the new configuration.
The local driver is a useful choice for many standalone installations because it performs automatic rotation by default and uses a more efficient format. However, the best choice depends on your logging and monitoring requirements.
Docker supports the none logging driver, but disabling logs removes the ability to retrieve container output through docker logs. This can make troubleshooting more difficult, so it should only be used when the operational requirements are understood.
Docker container logs can consume substantial disk space when applications generate continuous output and log rotation is not configured.
Start by identifying the largest log files and the containers responsible for them. Then configure max-size and max-file, or consider the local logging driver where appropriate.
For existing deployments, remember that containers must be recreated to receive updated logging options.
Combining proper log rotation with application-level error monitoring helps prevent Docker log growth from becoming a recurring Linux server storage problem.
Introduction Border Gateway Protocol (BGP) is the routing protocol used to exchange network reachability information…
Introduction A Linux server can experience connection failures even when its network interface is working…
Introduction TCP retransmissions are an important indicator of network reliability and performance. When a Linux…
Open Shortest Path First (OSPF) is a link-state routing protocol widely used in enterprise networks…
Group Policy is one of the most important management features in Windows Server Active Directory…
Windows DNS servers play an essential role in Active Directory environments, allowing computers, servers, applications,…