Docker runs applications in containers and captures their standard output and standard error through a logging driver. These are the streams normally read by docker logs; files an application writes inside its container need separate collection.
To clear Docker logs safely, first identify the container's logging driver and preserve any history you need. For json-file, plan to replace the selected container with explicit rotation limits. Docker's logs command has no clearing option, and Docker warns against editing or truncating its managed log files. Docker logs reference, JSON file driver.
The distinction matters when a host runs short of storage. Viewing fewer lines does not free space. Restarting a container does not recreate it. Changing daemon defaults does not change an existing container's logging settings. Rotation limits future growth by discarding older local history; it does not preserve that history elsewhere.
View the logs you still have
Identify the exact container in the correct Docker context, then read a bounded window:
docker ps --all --format '{{.ID}}\t{{.Names}}\t{{.Status}}'
docker logs --since 30m --tail 100 --timestamps CONTAINER
Replace CONTAINER with a verified name or ID. Add --follow to watch new output, then stop the stream when finished. The default tail is all retained lines. Use a positive integer: Docker interprets a negative or non-integer tail value as all.
For a fixed interval, use explicit UTC bounds:
docker logs --since '2026-11-03T14:00:00Z' \
--until '2026-11-03T14:15:00Z' \
--tail 200 --timestamps CONTAINER
These commands select records the driver can still read. They cannot recover rotated or uncollected output. Docker-added timestamps describe capture time and may differ from timestamps inside application messages. --until requires API 1.35 or later. Docker logs options.
For Compose V2, select the intended project and service:
docker compose -p storefront -f compose.yaml logs \
--since 30m --tail 100 --timestamps api
Here api is a Compose service name. Check the project name and file path before running the command. See the Compose logs guide for service and replica selection, or the Docker logs command reference for more viewing examples.
Why Docker log files grow
The json-file driver wraps each captured record with its stream and timestamp. Its max-size default is unlimited. Setting max-file alone does not enable rotation: it takes effect only when max-size is set. When rotation exceeds the configured file count, Docker removes the oldest file. JSON file retention options.
Docker recommends the local driver where compatibility permits. It rotates and compresses logs by default, using five files of 20 MB each before compression. That is a size policy, not a guaranteed number of hours of history. A collector that expects json-file records must not be assumed to understand local storage. Local driver documentation.
Storage paths vary with the driver, Docker data-root and installation. Docker Desktop stores Engine data inside its Linux environment; rootless installations also need their own path assumptions. A reported log path is not permission to edit the file. Both file-based drivers reserve their storage for Docker's own use.
How to reclaim Docker log space safely
These checks apply to Docker Engine operators handling container-related disk pressure. They help identify the affected storage, save useful evidence and replace only the intended workload. They do not guarantee that a completely full filesystem has enough room for replacement, or that logs are the only cause of pressure.
Identify the driver and affected filesystem
Inspect selected fields rather than dumping the full container configuration, which may expose secrets:
docker info --format '{{.LoggingDriver}}'
docker inspect --type=container --format \
'id={{.Id}} driver={{.HostConfig.LogConfig.Type}} max-size={{index .HostConfig.LogConfig.Config "max-size"}} max-file={{index .HostConfig.LogConfig.Config "max-file"}}' \
CONTAINER
The first command reports the daemon's current default. The second reports the selected container's creation-time settings. Missing options mean no explicit value is recorded there; interpret them using that driver's defaults. Logging-driver configuration.
On a conventional Linux Engine host, find the Docker data-root and check its filesystem:
docker info --format '{{.DockerRootDir}}'
Run df -h /actual/docker/data-root and df -i /actual/docker/data-root on the machine hosting that path. Substitute the reported path. The second command checks available inodes, which filesystems also need to create files. A remote Docker client must not measure its own local filesystem instead.
docker system df provides context about Docker resources, but its container size is not a measurement of retained log bytes. Compare filesystem capacity before and after the targeted change. Other writes can affect that comparison. Docker disk-usage reference.
If the filesystem is full, stop avoidable log production through the application's supported controls or a planned stop of the affected workload. Arrange capacity before attempting replacement. Do not assume pulling an image or recreating a container will succeed without free space.
Preserve a bounded log window
Choose the interval needed for investigation. Save it to an approved location with enough capacity, preferably on another filesystem when the Docker filesystem is under pressure:
(
umask 077
docker logs --since 30m --tail 500 --timestamps CONTAINER \
> /approved-evidence/checkout-before-replacement.log 2>&1
)
Use a new filename in a protected directory you control; shell redirection overwrites an existing file. Check the command's exit status and inspect the saved content. The file includes both application streams and any Docker error output. Five hundred lines is a chosen cap, not proof that the entire interval was preserved.
Logs can contain credentials and personal data. Restrict access, retain only what is needed and sanitize excerpts before sharing. If a central collector is already running, verify receipt before removing the source container. A successful local read does not establish successful delivery elsewhere.
Replace only the selected workload
Before replacement, verify the image, deployment definition, mounted data and recovery procedure. Files stored only in the container's writable layer are lost when that container is removed. Check that required data is stored persistently and backed up. Expect a service interruption unless the deployment has a separate availability mechanism.
For a Compose-managed service, add a logging policy to its existing service definition. This is a fragment to merge, not a complete deployment:
services:
api:
logging:
driver: json-file
options:
max-size: "12m"
max-file: "4"
Choose limits from measured output and the local history you need. Review the selected project's configuration, then deliberately recreate only that service:
docker compose -p storefront -f compose.yaml up \
-d --no-deps --force-recreate api
This stops and replaces the selected service's containers. --no-deps prevents starting linked services; it does not prevent disruption to callers that depend on api. Compose preserves mounted volumes during recreation, but that does not protect files left in the writable layer. Do not add volume-removal or anonymous-volume-renewal flags. Compose logging configuration, Compose recreation behavior.
For a standalone container, use its maintained deployment definition to create the replacement. Avoid reconstructing a production docker run command from memory. After a controlled stop, docker container rm EXACT_ID removes only the selected container; it is destructive and removes access to that instance's local history. Avoid force removal and volume-deletion flags. Container removal reference.
Verify limits and available space
Record the replacement's new ID and repeat the narrow logging inspection. Confirm that it reports the intended driver and both limits. A restart with the same ID is not evidence of recreation.
Then check service health, fresh log output and the same filesystem's available capacity. Configuration proves which limits were assigned. Older numbered events disappearing during a controlled test demonstrates bounded local retention. A filesystem measurement establishes available space at that moment. These are three different checks.
A daemon-wide policy can also set defaults, but it requires a daemon restart and applies only to newly created containers. Existing containers keep their settings until recreated. Docker daemon logging defaults.
Try bounded rotation on a disposable container
Use a development Engine with spare capacity, never a disk already under pressure. This exercise creates a container, emits 300 short synthetic events and removes that container before recreating it with smaller limits. It does not touch Docker-managed files or change daemon defaults.
Use an approved Alpine image already present locally. Replace the example tag if necessary. Choose an unused container name and record versions first:
docker version --format '{{.Server.Version}}'
docker compose version
Create the first container with an explicit 1 MB limit:
docker run --name log-retention-demo \
--log-driver json-file --log-opt max-size=1m --log-opt max-file=2 \
alpine:3.22 sh -c '
i=1
while [ "$i" -le 300 ]; do
printf "rotation-demo seq=%03d service=checkout-demo payload=abcdefghijklmnopqrstuvwxyz0123456789\n" "$i"
i=$((i + 1))
done
'
The container exits after producing its bounded output. Record its ID and effective options with the earlier inspection command. Read its retained events:
docker logs --tail 300 log-retention-demo
Measure the affected filesystem, then remove this disposable container by its verified ID:
docker container rm EXACT_DEMO_ID
Repeat the same docker run command with max-size=2k and max-file=2. Record the new ID and inspect the effective options again. Read up to 300 lines and compare the first and last sequence numbers with the first run.
With the smaller limits, older events should age out while recent events remain. Determine the actual retained range from your output; record counts depend on Docker's wrapped record sizes and rotation behavior. Merely seeing the last 20 lines with --tail 20 would not demonstrate rotation because the read command itself hides earlier lines.
Measure filesystem capacity before removal, after removal and after recreation. This small exercise may produce no visible change in rounded df -h output. Do not turn that into a claim that nothing was freed, or invent a reclaimed-byte total. Remove the final stopped demo container by its verified ID when finished.
Keep useful history across container replacement
For application events that must survive local rotation, establish central collection before replacing the source. Fluxtail's Docker collection guidance provides the next step. The collection path must match the actual driver and runtime storage.
For a controlled test, send a unique, non-sensitive marker through the application's normal logger. Do not assume output from docker exec ... echo enters the main container log stream. In the disposable exercise, the numbered rotation-demo lines can serve as markers if collection is configured before each run.
Compare the locally emitted sequence with rows actually received in Fluxtail. Record the container instance and time window. In Live Tail, search for the marker text; narrow by service and host only after checking that the collector populated those fields correctly. A service=checkout-demo string inside a message does not automatically become a service field.
After removing the old container, check whether its previously received markers remain available within the destination's retention period. Those rows establish what was retained, not that every event arrived. Fluxtail does not reclaim Docker disk space or recover history that was never collected.
Why Docker logs may be empty or incomplete
An empty result can mean the wrong container, project or interval was selected. A replacement has a new identity and does not inherit the removed instance's local history. An application writing only to an internal file also will not appear in stdout/stderr collection.
Driver behavior matters too. Some remote drivers use Docker's local readback cache. Disabling that cache for a driver without read support can make docker logs unavailable. The none driver intentionally provides no captured container logs. Remote delivery failures, cache failures and full non-blocking buffers can also lose output. Dual-logging behavior and limits.
Check source output, local retention and received records separately. Keep the container ID, driver, time window and collection gaps with your investigation notes. Missing log rows alone do not prove that the application did nothing.