Skip to content

Docker Cheat Sheet

Docker cheatsheet providing an advanced, structured reference for Docker CLI, container lifecycle management, image handling, Dockerfile instructions, volumes, networking, inspection, cleanup, and Docker Compose.

Docker Architecture

Docker packages applications into images which are instantiated as containers running on the Docker Engine.

Image -> Container -> Runtime
docker info

docker run

Create and start a new container from an image.

docker run [OPTIONS] IMAGE[:TAG] [COMMAND]
docker run -d -p 8080:80 --name web nginx

docker ps

List running or all containers.

docker ps
docker ps --all
docker ps --all
CONTAINER ID   IMAGE   STATUS         NAMES
e91c1f2d3a4b   nginx   Up 2 minutes   web

docker stop

Stop a running container.

docker stop CONTAINER
docker stop web

docker start

Start an existing container.

docker start CONTAINER
docker start web

docker rm

Remove containers.

docker rm CONTAINER
docker rm -f CONTAINER
docker rm web

docker exec

Execute a command inside a running container.

docker exec [OPTIONS] CONTAINER COMMAND
docker exec -it web bash

docker logs

View container logs.

docker logs CONTAINER
docker logs -f CONTAINER
docker logs -f web

docker images

List local images.

docker images
docker images
REPOSITORY   TAG     IMAGE ID       SIZE
nginx        latest  a6bd71f48f68   187MB

docker pull

Download an image.

docker pull IMAGE[:TAG]
docker pull nginx:latest

docker push

Upload an image to a registry.

docker push IMAGE
docker push user/app:1.0

docker build

Build an image from a Dockerfile.

docker build [OPTIONS] PATH
docker build -t app:1.0 .

docker rmi

Remove images.

docker rmi IMAGE
docker rmi nginx

docker image prune

Remove unused images.

docker image prune
docker image prune -a
docker image prune -a

docker inspect

Inspect Docker objects.

docker inspect OBJECT
docker inspect web

docker stats

Display resource usage.

docker stats
docker stats
CONTAINER   CPU %   MEM USAGE
web         0.10%   6MiB

docker system prune

Remove unused Docker data.

docker system prune
docker system prune -a
docker system prune -a

Docker Volumes

Volumes persist data beyond container lifecycle.

docker volume ls
docker volume create VOLUME
docker volume create app_data
docker run -v app_data:/data nginx

Docker Networking

Networks enable container communication.

docker network ls
docker network create NETWORK
docker network create backend
docker run --network backend nginx

Dockerfile Instructions

Dockerfile defines how images are built.

FROM image
RUN command
CMD ["exec","param"]
ENTRYPOINT ["exec","param"]
ENV key=value
EXPOSE port
COPY src dest
WORKDIR path
VOLUME path
USER user
ARG name
LABEL key=value
HEALTHCHECK CMD command
FROM nginx:latest
WORKDIR /app
COPY . .
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

docker compose up

Create and start services.

docker compose up
docker compose up -d
docker compose up -d

docker compose down

Stop and remove services.

docker compose down
docker compose down