// cheat sheets / docker-essentials
Docker quick reference
Images, containers, volumes, networks and Compose: the commands you use every day.
Write Dockerfile→Build Image→Run Container→Manage & Debug↺
CommandsBeginner#docker#containers#command-line
| Command | Description |
|---|
docker run -d -p 80:80 --name my-web nginx | Run a new container from an image, mapping ports and naming it. |
docker ps -a | List all running and stopped containers. |
docker stop my-web | Stop a running container gracefully. |
docker rm my-web | Remove a stopped container. Use -f to force removal. |
docker exec -it my-web bash | Opens an interactive shell inside a running container (use sh if the image has no bash). |
docker logs my-web | Shows a container’s output; add -f to follow it. |
| Command | Description |
|---|
docker build -t my-app:1.0 . | Build an image from a Dockerfile in the current directory. |
docker pull ubuntu:latest | Download an image from Docker Hub. |
docker images | List all local Docker images. |
docker rmi my-app:1.0 | Remove a local image. Use -f to force removal if in use. |
docker push my-registry/my-app:1.0 | Upload an image to a registry. |
- Volume — A persistent data store managed by Docker, independent of container lifecycle.
docker volume create my-data — Create a named volume.docker volume ls — List all Docker volumes.docker run -v my-data:/app/data --name db-app my-db-image — Mount a named volume into a container.docker volume rm my-data — Remove a volume. WARNING: Deletes all data in the volume.
- Bridge Network — Default network for containers on the same host to communicate.
docker network create my-net — Create a custom bridge network.docker run --network my-net --name web-app my-web-image — Connect a container to a specific network.docker network connect my-net another-container — Connect an existing container to a network.docker network inspect my-net — Show detailed information about a network.
| Command | Description |
|---|
docker compose up -d | Creates and starts the services in compose.yaml, in the background. |
docker compose down | Stops and removes the containers and networks; add -v to remove volumes too (deletes data). |
docker compose build | Builds or rebuilds the service images. |
docker compose ps | Lists the containers of the current Compose project. |
docker compose exec web sh | Runs a command (here a shell) in a running service container. |
docker compose logs -f | Shows the services’ output and keeps following it. |
docker system prune — Removes stopped containers, unused networks, dangling images and unused build cache. Asks before deleting.docker system prune -a — As above, plus every image no container uses. Expect to download images again.docker volume prune — Remove all unused local volumes. WARNING: Deletes data.docker image prune -a — Removes every image that no container uses.