← All sheets

Docker

Containers, images, Dockerfiles and Compose at a glance.

Containers

Command Description
docker run -d -p 8080:80 --name web nginx Run detached, map port 8080 to 80
docker run -it --rm alpine sh Interactive shell, removed on exit
docker ps Running containers
docker ps -a All containers
docker stop <name> Stop a container
docker rm <name> Remove a container
docker logs -f <name> Follow logs
docker exec -it <name> sh Shell into a running container

Images

Command Description
docker build -t app:latest . Build from Dockerfile in current folder
docker images List images
docker pull <image> Download an image
docker tag app user/app:1.0 Tag an image
docker push user/app:1.0 Push to registry
docker rmi <image> Remove an image

Volumes and networks

Command Description
docker volume ls List volumes
docker run -v data:/app/data <image> Named volume
docker run -v "$(pwd)":/app <image> Bind mount current folder
docker network create <name> Create network
docker run --network <name> <image> Attach to network

Cleanup

Command Description
docker system df Disk usage
docker container prune Remove stopped containers
docker image prune -a Remove unused images
docker system prune -a --volumes Remove everything unused

Dockerfile

FROM node:22-alpine AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
Instruction Description
FROM Base image
WORKDIR Set working directory
COPY / ADD Copy files into the image
RUN Run a command at build time
ENV Set environment variable
EXPOSE Document a port
CMD Default command (overridable)
ENTRYPOINT Fixed executable

Compose

services:
  web:
    build: .
    ports:
      - "8080:80"
    depends_on:
      - db
  db:
    image: postgres:17
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data:
Command Description
docker compose up -d Start in background
docker compose up --build Rebuild then start
docker compose down Stop and remove
docker compose down -v Also remove volumes
docker compose logs -f web Follow service logs
docker compose exec web sh Shell into service