> dimih_

< back

docker \

docker engine 29.10 | compose 5.8 | checked nov 2026 | docs

run

  • docker run -d --name web -p 8080:80 nginxbackground, host 8080 to 80
  • docker run --rm -it alpine shthrowaway shell
  • docker run -d --restart unless-stopped appback after crashes and reboots
  • docker run -e LOG=debug --env-file .env appenv vars, inline or from a file
  • docker run -v data:/var/lib/app appnamed volume
  • docker run -v "$PWD":/src -w /src appbind mount the current dir
  • docker run --network appnet appjoin a user network

containers

  • docker ps -astopped ones too
  • docker stop websigterm, sigkill after 10s
  • docker start web
  • docker rm -f webkill + remove
  • docker logs -f --tail 100 weblast 100 lines, then follow
  • docker exec -it web shshell in a running container
  • docker cp web:/etc/nginx/nginx.conf .copy out; swap the args to copy in
  • docker stats --no-streamcpu and memory, once
  • docker inspect webfull config as json

images

  • docker imageslocal images and sizes
  • docker pull nginx:alpinedownload without running
  • docker tag app:1.0 registry.example.com/team/app:1.0name it for a registry
  • docker login registry.example.comcredentials for push and pull
  • docker push registry.example.com/team/app:1.0upload
  • docker rmi app:olddelete a local image

build

  • docker build -t app:1.0 .Dockerfile in the current dir
  • docker build -f Dockerfile.prod -t app .another Dockerfile
  • docker build --build-arg VERSION=1.2 -t app .sets ARG VERSION
  • docker build --no-cache -t app .rerun every step
  • docker build --platform linux/amd64,linux/arm64 -t registry.example.com/app:1.0 --push .multi-arch, straight to the registry

dockerfile

go app in two stages
# build stage: the full go toolchain
FROM golang:1.27-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /app .

# final stage: only the binary
FROM alpine:3.24
RUN adduser -D -H -u 10001 app
COPY --from=build /app /usr/local/bin/app
USER app
EXPOSE 8080
ENTRYPOINT ["app"]

compose

  • docker compose up -dbuild if needed, start in the background
  • docker compose up -d --buildrebuild first
  • docker compose downstop, remove containers and networks
  • docker compose down -valso named volumes
  • docker compose psservices and their state
  • docker compose logs -f apifollow one service
  • docker compose exec api shshell in a running service
  • docker compose run --rm api npm testone-off container
  • docker compose pullnewer images; then up -d

compose.yaml

api + postgres
services:
  api:
    build: .  # rebuilt by up --build
    ports:
      - "8080:8080"
    environment:
      DATABASE_URL: postgres://app:app@db/app
    depends_on:
      db:
        condition: service_healthy  # waits for it
    restart: unless-stopped

  db:
    image: postgres:18
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: app  # example only
    volumes:
      - pgdata:/var/lib/postgresql  # 18+ path
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
      interval: 5s

volumes:
  pgdata:  # kept by down, removed by down -v

volumes & networks

  • docker volume lsevery volume
  • docker volume create datadocker run -v data:/path makes it too
  • docker volume rm datadeletes its data
  • docker network ls
  • docker network create appnetcontainers on it reach each other by name
  • docker network connect appnet webattach a running container

cleanup

  • docker system dfwhat takes the space
  • docker system prunestopped containers, unused networks, dangling images, build cache
  • docker system prune -a --volumesplus unused images and anonymous volumes
  • docker image prune -aevery image without a container