Skip to content
AI Stack Nest
2 min read · updated 18 Nov 2026

Docker Basics Cheat Sheet

Core Docker concepts and the most common commands for building, running, and managing containers

Core Concepts

TermWhat it means
ImageA read-only template that describes a container's filesystem and configuration
ContainerA running instance of an image, isolated from the host
DockerfileA text file with instructions to build an image
RegistryA storage service for images (Docker Hub is the public default)
VolumeA persistent storage area that survives container restarts
NetworkAn isolated virtual network containers can join to communicate

Building Images

CommandWhat it does
docker build -t name:tag .Builds an image from the Dockerfile in the current directory
docker build -f path/Dockerfile .Builds using a Dockerfile at a specific path
docker imagesLists all local images
docker rmi <image>Removes an image
docker pull <image>Downloads an image from the registry
docker push <image>Uploads an image to the registry

Running Containers

CommandWhat it does
docker run <image>Creates and starts a container
docker run -it <image>Runs with interactive terminal
docker run -d <image>Runs in the background (detached)
docker run -p 8080:80 <image>Maps host port 8080 to container port 80
docker run --name myapp <image>Assigns a name to the container
docker run -v /host:/container <image>Mounts a host directory as a volume
docker run --rm <image>Removes the container when it exits

Managing Containers

CommandWhat it does
docker psLists running containers
docker ps -aLists all containers, including stopped ones
docker stop <container>Gracefully stops a running container
docker start <container>Starts a stopped container
docker restart <container>Stops and starts a container
docker rm <container>Removes a stopped container
docker rm -f <container>Force-removes a running container

Inspecting and Debugging

CommandWhat it does
docker logs <container>Shows a container's output
docker logs -f <container>Follows the output in real time
docker exec -it <container> shOpens a shell inside a running container
docker inspect <container>Shows detailed container configuration as JSON
docker statsLive resource usage for running containers

Volumes and Networks

CommandWhat it does
docker volume create <name>Creates a named volume
docker volume lsLists all volumes
docker volume rm <name>Removes a volume
docker network create <name>Creates a network
docker network lsLists networks
docker run --network <name> <image>Runs a container on a specific network

Minimal Dockerfile Example

FROM python:3-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

Cleanup

CommandWhat it does
docker system pruneRemoves stopped containers, unused images, and networks
docker system prune -aAlso removes images not used by any container

Warning: docker system prune -a deletes every image that no container is using. Check docker images first, because you will have to download them again.

More cheat sheets

Not sure your computer can run a model? Use the will-it-run checker.