A crisp, practical guide to containers—focused on doing. Save time with copy‑ready commands, simple examples, and fixes to real errors.
docker run hello-world
docker pull nginx
docker run -p 8080:80 nginx
→ open localhost:8080
docker ps
→ copy CONTAINER ID → docker stop <id> && docker rm <id>
Tip: Map ports host:container
. If 8080 is busy, map 9090:80.
Track progress. Your checks save to your browser (localStorage).
Goal: Build → Run → Persist → Network → Compose → Publish
Filter by topic and click to copy commands. Search live.
Small, production‑ready-ish image with caching and non‑root user.
# syntax=docker/dockerfile:1
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production PORT=8080
COPY --from=deps /app/node_modules ./node_modules
COPY . .
USER node
EXPOSE 8080
CMD ["node","server.js"]
Tip: Use multi‑stage builds to keep runtime images small.
Web + DB with a named volume and network.
services:
web:
build: .
ports:
- "8080:8080"
environment:
- DB_HOST=db
depends_on:
- db
networks: [appnet]
db:
image: postgres:16
environment:
- POSTGRES_PASSWORD=changeme
volumes:
- pgdata:/var/lib/postgresql/data
networks: [appnet]
volumes:
pgdata:
networks:
appnet:
Remember to secure secrets (use env files, secret managers).
Another process is listening on that host port. Choose a free port or stop the process.
# find a free port quickly
# try 9090 instead of 8080
$ docker run -p 9090:80 nginx
On Linux, mount options or user mismatch cause this. Run as a user that owns the volume path or adjust permissions.
$ docker run -u $(id -u):$(id -g) -v $(pwd)/data:/data app
The main process ended. Use a long‑running command (server) or tail -f
during debugging.
$ docker run yourapp tail -f /dev/null
Put containers on the same user‑defined network, then use the service name as the hostname.
$ docker network create appnet
$ docker run --network appnet --name api yourapi
$ docker run --network appnet curlimages/curl curl http://api:8080/health
Memory Hook:
Image = Recipe • Container = Cooked dish • Volume = Fridge • Network = Dining table
Use rate‑limited pulls wisely—authenticate with Docker Hub.