Docker Commands Cheat Sheet

If you use Docker long enough, you eventually hit the same wall:

  • Containers are running… but nothing works

  • Logs are empty or useless

  • You forget the exact command to “just get inside the thing”

  • Disk space mysteriously vanishes

This Docker cheat sheet isn’t a full reference manual.
It’s the 90% of Docker commands you’ll actually use, written in plain English, so you can move fast when something breaks.

Bookmark it. You’ll be back.


Docker Mental Model (30-Second Primer)

Before commands, anchor these concepts:

  • Image → A blueprint (read-only)

  • Container → A running (or stopped) instance of an image

  • Volume → Persistent data outside container lifecycle

  • Network → How containers talk to each other

  • Dockerfile → Instructions to build an image

  • Docker Compose → Runs multi-container apps

If this mental model clicks, Docker becomes predictable instead of frustrating.


Container Lifecycle Commands

docker run

Create and start a new container.

docker run nginx

Most-used flags:

  • -d → run in background

  • -p 8080:80 → map ports

  • --name myapp → name container

  • -v host:container → mount volume

  • --env KEY=value → environment variable

Example:

docker run -d -p 8080:80 --name web nginx

docker start

Start an existing container.

docker start my_container

docker stop

Gracefully stop a container.

docker stop my_container

docker restart

Quick reset (stop + start).

docker restart my_container

docker rm

Delete a container (must be stopped).

docker rm my_container

Force remove:

docker rm -f my_container

Inspecting & Debugging Containers

docker ps

List running containers.

docker ps

Include stopped containers:

docker ps -a

docker logs

View container output.

docker logs my_container

Follow logs:

docker logs -f my_container

docker exec

Run a command inside a running container.

docker exec -it my_container bash

If bash doesn’t exist (Alpine images):

docker exec -it my_container sh

This is your “open the sealed box” command.


docker inspect

View detailed container configuration.

docker inspect my_container

Common uses:

  • Find container IP

  • Check mounted volumes

  • Confirm environment variables

  • Debug port bindings


Image Commands

docker images

List local images.

docker images

docker pull

Download an image.

docker pull postgres:16

docker build

Build an image from a Dockerfile.

docker build -t myapp .

docker rmi

Remove an image.

docker rmi my_image

Force:

docker rmi -f my_image

Volumes & Persistent Data

docker volume ls

List volumes.

docker volume ls

docker volume inspect

See where data lives on disk.

docker volume inspect my_volume

docker volume rm

Delete a volume.

docker volume rm my_volume

⚠️ This deletes data permanently.


Networking Commands

docker network ls

List networks.

docker network ls

docker network inspect

See connected containers.

docker network inspect bridge

docker network create

Create a custom network.

docker network create my_network

Custom networks = cleaner container-to-container communication.


Docker Cleanup Commands

docker system df

Check disk usage.

docker system df

docker system prune

Remove unused containers, images, and networks.

docker system prune

Aggressive cleanup:

docker system prune -a

If Docker is eating your disk space, this is usually the fix.


Docker Compose Cheat Sheet

docker compose up

Start all services.

docker compose up

Detached:

docker compose up -d

docker compose down

Stop and remove everything.

docker compose down

Remove volumes too:

docker compose down -v

docker compose ps

List running services.

docker compose ps

docker compose logs

View service logs.

docker compose logs -f

docker compose exec

Run a command inside a service.

docker compose exec app bash

Docker Debugging Shortcuts (Memorize These)

  • Container won’t start?docker logs

  • Need shell access?docker exec -it

  • Port not working?docker inspect

  • Disk full?docker system prune

  • Data missing? → check volumes

  • Multiple containers? → Docker Compose


Final Thought

Docker isn’t hard.

It’s just unforgiving when you don’t know which command unlocks which door.

This cheat sheet covers the commands that matter—the ones you’ll actually use under pressure.

Download Your FREE

Dev Stack Starter Guide

Build, automate, and launch faster—see the automation stack developers and agencies are switching to.

  • ✅ API Templates & Code Snippets
  • ✅ Done-for-You Automation Workflows
  • ✅ Step-by-Step Funnel & CRM Guide
  • ✅ Free for Developers, Freelancers, & SaaS Builders











We Respect Your Privacy