Skip to content

// cheat sheets / docker-essentials

Docker quick reference

Images, containers, volumes, networks and Compose: the commands you use every day.

CommandsBeginner#docker#containers#command-line

1. Container Lifecycle

CommandDescription
docker run -d -p 80:80 --name my-web nginxRun a new container from an image, mapping ports and naming it.
docker ps -aList all running and stopped containers.
docker stop my-webStop a running container gracefully.
docker rm my-webRemove a stopped container. Use -f to force removal.
docker exec -it my-web bashOpens an interactive shell inside a running container (use sh if the image has no bash).
docker logs my-webShows a container’s output; add -f to follow it.

2. Image Management

CommandDescription
docker build -t my-app:1.0 .Build an image from a Dockerfile in the current directory.
docker pull ubuntu:latestDownload an image from Docker Hub.
docker imagesList all local Docker images.
docker rmi my-app:1.0Remove a local image. Use -f to force removal if in use.
docker push my-registry/my-app:1.0Upload an image to a registry.

3. Data Volumes

  • 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.

4. Networking

  • 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.

5. Docker Compose

CommandDescription
docker compose up -dCreates and starts the services in compose.yaml, in the background.
docker compose downStops and removes the containers and networks; add -v to remove volumes too (deletes data).
docker compose buildBuilds or rebuilds the service images.
docker compose psLists the containers of the current Compose project.
docker compose exec web shRuns a command (here a shell) in a running service container.
docker compose logs -fShows the services’ output and keeps following it.

6. Cleaning Up

  • 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.
archhyarchhy.com/cheat-sheets/docker-essentialsMake your own at archhy.com

Draw your own, with real cloud icons.

Start drawing, free

No account needed to start.