Skip to main content

Core Engine Commands

Commands for understanding your Docker installation, checking system health, and diagnosing host-level issues.

System Information

docker version

Show client and server versions. Essential for diagnosing feature availability and API compatibility:

docker version

# Compact format
docker version --format '{{.Server.Version}}'

docker info

Show daemon runtime details -- storage driver, logging config, security options, number of containers/images:

docker info

# Check specific fields
docker info --format '{{.StorageDriver}}'
docker info --format '{{json .SecurityOptions}}'

docker context ls

Show available Docker contexts (environments). Always verify before running commands on production:

docker context ls

# Switch context
docker context use production

Disk Usage

docker system df

High-level storage summary showing total, active, and reclaimable space:

docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images 12 5 2.3GB 1.1GB (47%)
Containers 5 2 120MB 50MB (41%)
Local Volumes 3 1 500MB 0B (0%)
Build Cache 0 0 0B 0B

Detailed Breakdown

# Per-image, per-container, per-volume sizes
docker system df -v

# Container writable layer sizes
docker ps -s

Event Monitoring

docker system events

Stream real-time daemon events (container start/stop, image pull, network connect, etc.):

# Follow all events
docker system events

# Events from the last 10 minutes
docker system events --since 10m

# Filter by event type
docker system events --filter type=container
docker system events --filter event=die

# Events for a specific container
docker system events --filter container=my-app
FilterValuesExample
typecontainer, image, volume, network, daemon--filter type=container
eventstart, stop, die, kill, create, destroy--filter event=die
containerName or ID--filter container=my-app
imageImage name--filter image=nginx

Cleanup Commands

# Remove stopped containers, dangling images, unused networks, build cache
docker system prune

# Also remove all unused images (not just dangling)
docker system prune -a

# Remove items older than 24 hours (safe for CI)
docker system prune -f --filter "until=24h"
Never Auto-Run

docker system prune -a --volumes removes everything not currently in use, including named volumes. Never put this in a cron job.

Formatting Output

Docker supports Go template formatting for any command:

# Custom ps output
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}\t{{.Ports}}'

# JSON output for scripting
docker ps --format '{{json .}}'

# Get specific inspect fields
docker inspect CONTAINER --format '{{.State.Status}}'
docker inspect CONTAINER --format '{{json .NetworkSettings.Networks}}'

Commonly Used Format Templates

TemplateWhat It Shows
{{.Names}}Container name
{{.Status}}Running status with uptime
{{.Image}}Image name:tag
{{.Ports}}Published port mappings
{{.Size}}Container disk size (with -s flag)
{{.State.Status}}Simple status (running/exited)
{{.Config.User}}User the container runs as
{{json .NetworkSettings}}Full network config as JSON

Diagnostic Quick Reference

GoalCommand
Check Docker versiondocker version
Check daemon configurationdocker info
Verify target environmentdocker context ls
Check disk usagedocker system df
Detailed disk breakdowndocker system df -v
Watch container events livedocker system events
Events from last 10 mindocker system events --since 10m
Safe cleanupdocker system prune
CI cleanup (24h old)docker system prune -f --filter "until=24h"

What's Next