RackUp IT - View Cloud Hosting Plans

Get started now or speak directly with our engineering team for specialized assistance.

Logo
DevelopmentWEB & APPCalculatorTOOLServicesProductBlogOur TeamCareers
View Plans
Home>Blog>Docker Logs: How to View, Tail, Find and Clear Container Logs
VPS Hosting

Docker Logs: How to View, Tail, Find and Clear Container Logs

Alex Vance
Alex Vance
Published Oct 13, 2026· Updated Nov 19, 2026•✓ Verified Expert Reviewed•3 min read
Docker Logs guide cover

Key Takeaways

  • ✓docker logs -f --tail 100 CONTAINER is the command you will use most.
  • ✓Log files live in /var/lib/docker/containers/ID/ID-json.log; docker inspect shows the exact path.
  • ✓Clear a log with truncate, never rm.
  • ✓Set max-size and max-file in daemon.json so logs cannot fill the disk again.

Table of Contents

  • •Docker Logs: How to View, Tail, Find and Clear Container Logs
  • •View and Tail Docker Logs
  • •Filter Logs by Time or Text
  • •Docker Compose Logs
  • •Where Are Docker Logs Stored?
  • •How to Clear Docker Logs Safely
  • •Stop Logs Filling the Disk: Log Rotation
  • •Why Are My Docker Logs Empty?
  • •Frequently Asked Questions
  • •Spend Less Time on Servers

Docker Logs: How to View, Tail, Find and Clear Container Logs

Docker captures everything a container writes to standard output and standard error and stores it as the container's log. That makes docker logs the first place to look when a container crashes, restarts or returns errors. This guide covers reading those logs, finding the files on disk, clearing them, and stopping them from growing forever.

View and Tail Docker Logs

# Everything the container has logged
docker logs web

# Follow new lines live (like tail -f)
docker logs -f web

# Only the last 100 lines, then keep following (-n is short for --tail)
docker logs -f --tail 100 web
docker logs -f -n 100 web

# Only new lines from now on
docker logs -f --tail 0 web

# Add timestamps
docker logs -t --tail 50 web

Press Ctrl+C to stop following; the container keeps running.

Filter Logs by Time or Text

# Last 10 minutes
docker logs --since 10m web

# A specific window
docker logs --since 2026-10-07T09:00:00 --until 2026-10-07T10:00:00 web

# Search for errors (2>&1 includes stderr)
docker logs web 2>&1 | grep -i error

The 2>&1 matters: docker logs replays the container's stderr on your stderr, so without it grep misses error output.

Docker Compose Logs

# All services
docker compose logs -f --tail=100

# One service
docker compose logs -f --tail=100 app

Where Are Docker Logs Stored?

With the default json-file logging driver on Linux, each container's log is a file at:

/var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log

Get the exact path for one container:

docker inspect --format='{{.LogPath}}' web
  • Docker Desktop (Mac and Windows): containers run inside a virtual machine, so the files are not on your normal disk. Use docker logs or the Desktop dashboard.
  • journald driver: logs go to the system journal. Read them with journalctl CONTAINER_NAME=web.
  • The Docker daemon's own log (not your containers): journalctl -u docker.

Check which driver a container uses with docker inspect --format='{{.HostConfig.LogConfig.Type}}' web.

How to Clear Docker Logs Safely

A busy container can write gigabytes of logs and fill a small VPS. To empty one container's log without stopping it:

sudo truncate -s 0 $(docker inspect --format='{{.LogPath}}' web)

Do not rm the file: Docker keeps it open, so the space is not freed and logging for that container breaks until it is recreated. Recreating the container (docker compose up -d --force-recreate app) also starts a fresh log.

To see which containers use the most space:

sudo du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail

Stop Logs Filling the Disk: Log Rotation

By default the json-file driver never rotates. Set limits for all new containers in /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Then sudo systemctl restart docker. This caps each container at about 30 MB of logs. It only applies to containers created after the change, so recreate existing ones. In Compose you can set it per service:

services:
  app:
    image: myapp
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

The local driver is another good option: it rotates by default and stores logs more compactly.

Why Are My Docker Logs Empty?

The app is probably writing to a file inside the container instead of stdout/stderr. Configure it to log to the console, or link the file to stdout the way the official Nginx image does (ln -sf /dev/stdout /var/log/nginx/access.log). Logs are also empty if the logging driver is none or sends logs elsewhere (syslog, a cloud service).

Running Nginx in a container? Its errors land in these logs; our Nginx errors guide explains what each one means.

Frequently Asked Questions

How do I tail Docker logs?
Run docker logs -f --tail 100 CONTAINER. It prints the last 100 lines and keeps streaming new ones.

Where are Docker container logs stored on Linux?
In /var/lib/docker/containers/ID/ID-json.log when using the default json-file driver. docker inspect --format='{{.LogPath}}' CONTAINER prints the exact path.

How do I clear Docker logs?
Truncate the log file with sudo truncate -s 0 and the path from docker inspect, or recreate the container. Do not delete the file.

Do Docker logs get deleted when a container is removed?
Yes. Removing the container with docker rm deletes its log file too. Ship important logs to an external system if you need to keep them.

How do I see logs of a container that keeps restarting?
docker logs --tail 50 CONTAINER works on stopped and restarting containers too, and usually shows the crash reason in the last few lines. To get a shell inside, see docker exec.

Spend Less Time on Servers

If managing Docker hosts, log rotation and disk space is taking time away from your product, RackUp IT managed hosting handles the server side for you, including monitoring, backups and SSL.

← Previous Articledocker exec: How to Run Commands and Open a Shell Inside a ContainerNext Article →Heroku Alternative: Where to Host Node, Laravel and Django Apps in 2026
Interactive 60-Second Tool

Unsure Which Cloud Hosting Plan Fits Your Site?

Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.

Free Migration 99.9% Uptime Target
Calculate My Hosting Build
Alex Vance
Written ByAlex Vance

Cloud Infrastructure Engineer.

99.9% Uptime Target

RackUp IT - View Cloud Hosting Plans

View Hosting Plans

View Hosting Plans

CONTENTS

  • Docker Logs: How to View, Tail, Find and Clear Container Logs
  • View and Tail Docker Logs
  • Filter Logs by Time or Text
  • Docker Compose Logs
  • Where Are Docker Logs Stored?
  • How to Clear Docker Logs Safely
  • Stop Logs Filling the Disk: Log Rotation
  • Why Are My Docker Logs Empty?
  • Frequently Asked Questions
  • Spend Less Time on Servers

Categories

  • VPS Hosting
  • DevOps & Tutorials
  • WordPress Hosting
  • Cloud Hosting
  • Server Stack
  • Networking & Security
  • Web Hosting / Managed Cloud
  • E-Commerce
  • Hosting & SEO
  • Hosting Benchmarks
  • Cloud Backup & DevOps
  • Managed VPS

Recent Posts

  • Vultr Alternatives in 2026: VPS Hosting for Developers Compared
  • Docker Port Mapping Explained: -p, EXPOSE and Compose ports
  • Bluehost Alternatives (2026): WordPress Hosting Without the Renewal Price Jump

Tags

Dockerdocker logsContainersDevOpsLinuxDisk Space

Related Posts

Vultr alternatives coverVPS Hosting
Nov 27, 2026

Vultr Alternatives in 2026: VPS Hosting for Developers Compared

Vultr's Regular Performance prices compared with DigitalOcean, Linode, Hetzner and a fixed-plan VPS at the 8 GB size, plus when container hosting fits better.

Read Article →
What is a VPS? Virtual private servers explainedVPS Hosting
Nov 20, 2026

What Is a VPS? Virtual Private Servers Explained

A VPS (virtual private server) is a virtual machine with its own operating system, resources and root access. How it works, uses, and when you need one.

Read Article →
Linode alternatives coverVPS Hosting
Nov 19, 2026

Linode (Akamai) Alternatives in 2026: VPS Hosting Compared

Linode's shared CPU prices from Akamai's own API, compared with DigitalOcean, Vultr and a fixed-plan VPS, plus when container hosting makes more sense.

Read Article →
Logo

Expert Web & App Development, UI/UX Design, Branding, and Consulting to scale your business.

Company

  • About Us
  • Blog
  • Contact
  • Our Team
  • Careers

Services

  • Web Development
  • App Development
  • UI/UX Design
  • Consulting
  • Managed WordPress VPS
  • Website Speed Test

Subscribe to our newsletter

We accept
  • bKash
  • Nagad
  • Rocket
  • Upay
  • CellFin
  • Meghna Pay
  • OK Wallet
  • Tap
  • mCash
  • DBBL Nexus
  • Visa
  • Mastercard
  • American Express
  • Crypto
Pay with Visa, Mastercard, American Express, DBBL Nexus, CellFin, Rocket, bKash, Tap, Meghna Pay, Nagad, mCash, Upay and OK Wallet. Verified by EPS

© 2026 Rackup IT Solution. All rights reserved.

Privacy PolicyTerms of Service