← Back to cheat sheets

Containers & Orchestration

Docker cheat sheet

Docker creates portable containers for consistent deployments.

On this page

Table of contents

Use this page for fast recall. Use Full documentation when you want the complete end-to-end path.

Quick workflow

A simple 5-step flow you can follow when using Docker in real work.

1) Setup

Install/run the tool and confirm version. Create a minimal config.

2) Small change

Do one small action end-to-end to prove the workflow.

3) Validate

Check output, logs, and status. Catch mistakes early.

4) Automate

Convert it into a repeatable script or pipeline step.

5) Productionize

Add safety: secrets, rollback, observability, and docs.

Workflows you will actually reuse

These are practical sequences you can copy into your own checklist or runbook.

Local dev container workflow

Goal: Run your app the same way locally as it runs in production.

- Build the image with a dev tag.

- Run with `--rm` and required env vars/ports.

- Inspect logs and confirm the health endpoint works.

- Package dependencies inside the image (avoid host coupling).

- Move to Compose for multi-service local environments.

Key Concepts

- Images

- Containers

- Networks

Learning path (high-level):

- Dockerfile basics

- Compose multi-service apps

- Image optimization

Quick Start

Build image

Command

docker build -t my-app .

Run container

Command

docker run -p 3000:3000 my-app

List containers

Command

docker ps

Common Commands

Short descriptions and practical intent. Search, filter, copy, and reuse.

Showing 31

Basics
docker version

Show client/server version.

Basics
docker info

Show runtime details (storage driver, cgroups).

Build
docker build -t my-app:dev .

Build an image from Dockerfile.

Build
docker build --no-cache -t my-app:dev .

Build without cache (debug build issues).

Build
docker history my-app:dev

Inspect image layers (size + commands).

Run
docker run --rm -p 3000:3000 my-app:dev

Run container and remove it on exit.

Run
docker run -it --rm my-app:dev sh

Start an interactive shell in the image.

Containers
docker ps

List running containers.

Containers
docker ps -a

List all containers.

Containers
docker logs <container>

Show container logs.

Containers
docker logs -f <container>

Follow logs (tail).

Containers
docker exec -it <container> sh

Open shell in a running container.

Containers
docker inspect <container>

Inspect container details (env, mounts, network).

Containers
docker stop <container>

Stop a running container.

Containers
docker rm <container>

Remove a container.

Images
docker rmi <image>

Remove an image.

Images
docker images

List local images.

Registry
docker tag my-app:dev myrepo/my-app:1.0.0

Tag image for pushing.

Registry
docker login

Login to a registry.

Registry
docker push myrepo/my-app:1.0.0

Push image to registry.

Registry
docker pull nginx:alpine

Pull an image from a registry.

Networking
docker network ls

List networks.

Networking
docker network inspect <net>

Inspect network config.

Storage
docker volume ls

List volumes.

Storage
docker volume inspect <vol>

Inspect a volume.

Compose
docker compose up -d

Start services in background.

Compose
docker compose ps

Show Compose service status.

Compose
docker compose logs -f

Follow Compose logs.

Compose
docker compose down -v

Stop services and remove volumes (dev reset).

Cleanup
docker system df

Show disk usage by Docker objects.

Cleanup
docker system prune

Clean unused docker resources.

Copyable snippets

Small blocks you can drop into your terminal, config, or runbook.

Minimal health-check style curl

bash

curl -fsS http://localhost:3000/health || echo "unhealthy"

Run a container with env + port

bash

docker run --rm -p 3000:3000 -e NODE_ENV=production my-app:1.0.0

Troubleshooting checklist

When things break, follow this order to stay calm and move fast.

- If build is slow: check `.dockerignore`, reduce context, and leverage layer caching.

- If container exits: read logs first, then run the image interactively to inspect config/env.

- If networking fails: verify published ports, container network, and DNS inside container.

- If disk usage is high: use `docker system df`, then prune safely in dev.

Pitfalls

The common mistakes that slow people down when using Docker.

- Building huge images (no `.dockerignore`, no multi-stage builds).

- Running as root in containers in production.

- Not pinning image tags (use digests or version tags).

Mini lab (practice)

Do these tasks in order. You will feel the tool instead of just reading about it.

- Write a minimal Dockerfile, build the image, run it, then inspect logs and environment variables.

- Use Compose to run 2 services and confirm networking between them.

- Optimize an image size using multi-stage build or `.dockerignore`.

Interview prompts

Use these to test if you truly understand the basics (and can explain them clearly).

- Explain the tool’s role in a real CI/CD pipeline from commit to production.

- Describe the most common failure you’ve seen with this tool and how you fixed it.

- What would you monitor/alert on for this tool in production?

Official Docs

https://docs.docker.com/