All Cheat SheetsDevOps
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:alpineRun interactive container with cleanupRemoves container on exit
docker run --rm -it node:20-alpine shList active containersShows running containers and ports
docker psList all containers (including stopped)Includes exited containers
docker ps -aStop and kill containersSIGTERM graceful vs SIGKILL immediate
docker stop my-app
docker kill my-appExecute command inside running containerOpen bash shell inside container
docker exec -it my-app /bin/bashImages & 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 imagesRemove imageDelete image from local cache
docker rmi my-app:1.0.0Prune unused images and build cacheFrees disk space
docker image prune -a
docker builder pruneLogs, Debugging & Inspection
Follow live logsStream last 100 log lines
docker logs -f --tail 100 my-appInspect container JSON metadataDetailed IP, mounts, and env config
docker inspect my-appView real-time resource statsLive CPU, memory, and I/O metrics
docker statsCopy file into/out of containerExtract container files locally
docker cp my-app:/app/logs ./logsDocker Compose
Start stack in backgroundBuilds and starts all defined services
docker compose up -dStop and remove stackStops services and deletes named volumes
docker compose down -vRebuild and restart stackForces fresh container image build
docker compose up -d --buildView compose stack logsFilter live logs by service
docker compose logs -f service-name