Cheatsheet
The Docker commands you use weekly, on one page.
Daily Docker
EXAMPLE
# Images docker build -t myapp:1.2.3 . docker build --target=build -t myapp:build . # stage docker build --build-arg NODE_ENV=production . docker image ls docker image prune -f docker pull node:20-alpine docker push myrepo/myapp:1.2.3 # Containers docker run --rm -it myapp:1.2.3 sh docker run -d --name api -p 3000:3000 -e DB_URL=... myapp:1.2.3 docker ps # running docker ps -a # all docker logs -f api docker exec -it api sh docker stop api && docker rm api docker container prune -f # Volumes + bind mounts docker run -v $(pwd):/app -w /app node:20 npm test docker volume create pgdata docker run -v pgdata:/var/lib/postgresql/data postgres:16 # Networks docker network create app docker run --network=app --name db postgres:16 docker run --network=app -e DB_HOST=db myapp # Compose docker compose up -d docker compose logs -f web docker compose exec web sh docker compose down -v # stop AND remove volumes (destructive) # Inspect + debug docker inspect api docker top api docker stats docker history myapp:1.2.3 # BuildKit cache and multi-platform docker buildx build --platform linux/amd64,linux/arm64 -t myapp:1.2.3 --push . # Disk usage docker system df docker system prune -a --volumes -f # nuke everything
Why it matters
Lean on prune and volumes; reach for compose when you have three or more services in dev. In production avoid running the docker socket inside containers - it is root on the host.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
# Build + run + push docker build -t img . docker run -d -p 8080:80 img docker push reg/img:tagTry it Yourself »
Discussion
Loading…