← All cheatsheets

Docker Cheatsheet

A practical Docker cheatsheet: run and inspect containers, build and manage images, drive docker compose, and clean up — copy-ready with editable placeholders. Destructive cleanup commands are flagged.

Explain a command

Run & manage containers

  • Run a container (detached, published port)
    docker run -d --name -p :
    · host = host port · container = container port
  • Run an interactive shell, remove on exit
    docker run --rm -it
  • Run with an env var and a volume
    docker run -d -e = -v :
  • List running containers
    docker ps
  • List all containers (incl. stopped)
    docker ps -a
  • Open a shell in a running container
    docker exec -it
  • Follow a container’s logs
    docker logs -f
  • Stop a container
    docker stop
  • Force-remove a containerdestructive
    docker rm -f
  • Get a container’s IP address
    docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
  • Live resource usage
    docker stats
  • Copy a file out of a container
    docker cp :

Images

  • Build an image from the current dir
    docker build -t .
  • List images
    docker images
  • Pull an image
    docker pull
  • Tag an image for a registry
    docker tag /
  • Push an image
    docker push
  • Remove an imagedestructive
    docker rmi

Compose

  • Start the stack (detached)
    docker compose up -d
  • Stop and remove the stack
    docker compose down
  • Stop the stack and delete its volumesdestructive
    docker compose down -v

    Also removes named volumes — data is lost.

  • Follow logs for a service
    docker compose logs -f
  • List compose services
    docker compose ps
  • Run a command in a service
    docker compose exec
  • Rebuild service images
    docker compose build --no-cache

Cleanup

  • Show disk usage
    docker system df
  • Remove dangling datadestructive
    docker system prune

    Removes stopped containers, unused networks, and dangling images.

  • Aggressively reclaim everything unuseddestructive
    docker system prune -a --volumes

    Also removes all unused images AND volumes — can delete a lot. Be sure.

28 commands. Copy-ready with editable placeholders — everything runs in your browser, nothing is sent to a server.