DevOps 4 min read

Docker Cheat Sheet: Day-to-Day Commands

Essential Docker commands for everyday use. Quick reference for container management, cleanup, and common operations.

MR

Moshiour Rahman

Advertisement

Overview

This is a collection of Docker commands I use daily. Bookmark this page as a quick reference guide for container management and cleanup operations.

Container Management

Stop All Running Containers

Use docker container stop with a list of all container IDs:

docker container stop $(docker container ls -aq)

This command:

  1. docker container ls -aq - Lists all container IDs (running and stopped)
  2. Passes them to docker container stop

Remove All Containers

Force remove all containers (running and stopped):

docker rm $(docker ps -aq) -f

Flags:

  • -a - All containers (not just running)
  • -q - Quiet mode (only IDs)
  • -f - Force removal (even if running)

Volume Management

Remove All Unused Volumes

After removing containers, clean up orphaned volumes:

docker volume prune

You’ll be prompted to confirm. Use -f to skip the prompt:

docker volume prune -f

List and Remove Specific Volumes

# List all volumes
docker volume ls

# Remove a specific volume
docker volume rm volume_name

# Remove multiple volumes
docker volume rm volume1 volume2 volume3

System Cleanup

Remove All Unused Objects

The nuclear option - removes stopped containers, unused networks, and dangling images:

docker system prune

Output:

WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all build cache
Are you sure you want to continue? [y/N]

Include Unused Volumes

Add --volumes to also remove unused volumes:

docker system prune --volumes

Force Without Confirmation

docker system prune -af --volumes

Flags:

  • -a - Remove all unused images (not just dangling)
  • -f - Force (no confirmation prompt)
  • --volumes - Include unused volumes

Image Management

Remove Dangling Images

Dangling images are layers with no tags and not referenced by any container:

docker image prune

Remove All Unused Images

docker image prune -a

List Images by Size

docker images --format "{{.Repository}}:{{.Tag}} - {{.Size}}" | sort -k2 -h

Container Logs

View Container Logs

# View all logs
docker logs container_name

# Follow logs (like tail -f)
docker logs -f container_name

# Last 100 lines
docker logs --tail 100 container_name

# Logs since a time
docker logs --since 2h container_name

Quick Reference Table

CommandDescription
docker psList running containers
docker ps -aList all containers
docker imagesList images
docker volume lsList volumes
docker network lsList networks
docker statsLive resource usage
docker top containerRunning processes in container
docker inspect containerDetailed container info

Docker Compose Commands

Start Services

# Start in foreground
docker-compose up

# Start in background
docker-compose up -d

# Rebuild and start
docker-compose up --build

Stop Services

# Stop services
docker-compose down

# Stop and remove volumes
docker-compose down -v

# Stop and remove images
docker-compose down --rmi all

View Logs

# All services
docker-compose logs

# Specific service
docker-compose logs service_name

# Follow logs
docker-compose logs -f

Useful Aliases

Add these to your .bashrc or .zshrc:

# Docker
alias dps='docker ps'
alias dpsa='docker ps -a'
alias dimg='docker images'
alias dexec='docker exec -it'
alias dlogs='docker logs -f'
alias dprune='docker system prune -af'

# Docker Compose
alias dc='docker-compose'
alias dcup='docker-compose up -d'
alias dcdown='docker-compose down'
alias dclogs='docker-compose logs -f'

Conclusion

These commands cover most day-to-day Docker operations. Keep this page bookmarked for quick reference!

Pro Tips:

  • Always be careful with prune commands in production
  • Use --dry-run when available to preview changes
  • Regularly clean up to save disk space

Advertisement

MR

Moshiour Rahman

Software Architect & AI Engineer

Share:
MR

Moshiour Rahman

Software Architect & AI Engineer

Enterprise software architect with deep expertise in financial systems, distributed architecture, and AI-powered applications. Building large-scale systems at Fortune 500 companies. Specializing in LLM orchestration, multi-agent systems, and cloud-native solutions. I share battle-tested patterns from real enterprise projects.

Related Articles

Comments

Comments are powered by GitHub Discussions.

Configure Giscus at giscus.app to enable comments.