Docker Power User: 15 Commands That'll Save Hours

Stop clicking through Docker Desktop. Real developers use the CLI. Here's your cheat sheet.

1. Clean Everything (docker system prune -a)

Removes:

  • Stopped containers
  • Unused networks
  • Dangling images
  • Build cache
docker system prune -a -f

Reclaims: Usually 5-20GB

2. One-Liner Container Run

docker run -d -p 8080:80 --name myapp nginx
  • -d = detached (runs in background)
  • -p 8080:80 = port mapping
  • --name myapp = easy to remember name

3. Execute Commands in Running Container

docker exec -it myapp /bin/bash

Now you're inside the container. Like SSH but faster.

4. View Logs (Live)

docker logs -f myapp

-f = follow (like tail -f)

5. Copy Files In/Out

# From host to container
docker cp file.txt myapp:/app/

# From container to host
docker cp myapp:/app/log.txt ./

6. Inspect Everything

docker inspect myapp | grep IPAddress

Get container IP, environment variables, mount points, everything.

7. Build with BuildKit (2x Faster)

DOCKER_BUILDKIT=1 docker build -t myapp .

BuildKit enables:

  • Parallel builds
  • Better caching
  • Secrets support

8. Multi-Platform Builds

docker buildx build --platform linux/amd64,linux/arm64 -t myapp .

One build, works on Intel and Apple Silicon.

9. Remove All Containers (Nuclear Option)

docker rm -f $(docker ps -aq)

-aq = all container IDs -f = force remove even if running

10. Image Size Check

docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"

Find bloated images.

11. Export/Import Images (No Registry)

# Export
docker save myapp > myapp.tar

# Import (different machine)
docker load < myapp.tar

Use case: Transferring images without internet.

12. Health Checks

HEALTHCHECK --interval=30s --timeout=3s \
  CMD curl -f http://localhost/ || exit 1

Docker auto-restarts unhealthy containers.

13. Resource Limits

docker run -m 512m --cpus=1.5 myapp
  • -m 512m = max 512MB RAM
  • --cpus=1.5 = max 1.5 CPU cores

Prevent one container from hogging resources.

14. Docker Compose Up (Detached)

docker-compose up -d

Starts all services in background.

View logs:

docker-compose logs -f service-name

15. Stats (Live Resource Usage)

docker stats

See CPU, memory, network I/O in real-time.


Bonus: Aliases to Save Even More Time

Add to .bashrc or .zshrc:

alias dps='docker ps'
alias dpa='docker ps -a'
alias di='docker images'
alias drm='docker rm -f'
alias drmi='docker rmi'
alias dex='docker exec -it'
alias dl='docker logs -f'

Now dps instead of docker ps.


Time saved: 30 seconds per command × 50 times/day = 25 minutes/day

That's 100 hours/year just from Docker shortcuts.

You're welcome (again).