Code BeautifierDev Tools

Docker CLI & Docker Compose Cheat Sheet

Essential commands for managing containers, images, volumes, networks, and compose stacks

Container Lifecycle

Run container in backgroundRuns detached with port mapping
docker run -d --name my-app -p 8080:80 nginx:alpine
Run interactive container with cleanupRemoves container on exit
docker run --rm -it node:20-alpine sh
List active containersShows running containers and ports
docker ps
List all containers (including stopped)Includes exited containers
docker ps -a
Stop and kill containersSIGTERM graceful vs SIGKILL immediate
docker stop my-app
docker kill my-app
Execute command inside running containerOpen bash shell inside container
docker exec -it my-app /bin/bash

Images & Dockerfile

Build image with tagBuilds from Dockerfile in current dir
docker build -t my-org/my-app:1.0.0 .
Build with specific DockerfileSpecify custom build file
docker build -f Dockerfile.prod -t my-app:prod .
List local imagesShows repository, tag, and size
docker images
Remove imageDelete image from local cache
docker rmi my-app:1.0.0
Prune unused images and build cacheFrees disk space
docker image prune -a
docker builder prune

Logs, Debugging & Inspection

Follow live logsStream last 100 log lines
docker logs -f --tail 100 my-app
Inspect container JSON metadataDetailed IP, mounts, and env config
docker inspect my-app
View real-time resource statsLive CPU, memory, and I/O metrics
docker stats
Copy file into/out of containerExtract container files locally
docker cp my-app:/app/logs ./logs

Docker Compose

Start stack in backgroundBuilds and starts all defined services
docker compose up -d
Stop and remove stackStops services and deletes named volumes
docker compose down -v
Rebuild and restart stackForces fresh container image build
docker compose up -d --build
View compose stack logsFilter live logs by service
docker compose logs -f service-name

Try Related In-Browser Tools