Docker CLI Cheatsheet
Container virtualization and orchestration syntax cheatsheet — cover runtimes, images, storage networking, and compose layouts.
Container Management
docker run -d -p 80:80 [img]
Run a container in the background (detached) with port forwarding.
docker run -d -p 8080:80 nginx
docker ps
List running containers. Add `-a` to show stopped ones.
docker ps -a
docker stop [id]
Stop a running container gracefully.
docker stop webserver-01
docker exec -it [id] bash
Open an interactive terminal session inside a container.
docker exec -it db-container bash
docker rm [id]
Remove a container instance from the host system.
docker rm -f test-api
Images Operations
docker build -t [name] .
Build a Docker image from a local Dockerfile in current directory.
docker build -t myapp:1.0 .
docker images
List all local Docker images stored on system.
docker images | grep myapp
docker rmi [img]
Remove one or more images from the host system.
docker rmi nginx:alpine
docker pull [img]
Download an image from Docker Hub repository.
docker pull postgres:15-alpine
Volumes & Compose
docker volume create [name]
Create a persistent volume mount for container data storage.
docker volume create pgdata
docker-compose up -d
Build and start all compose stack services in background.
docker-compose up -d --build
docker-compose down
Stop and remove all containers, networks, and images in compose.
docker-compose down -v
No matching syntax found
Verify your query spelling or try searching another keyword.