Docker for Developers: From Zero to Production
Docker is the standard for packaging applications. This tutorial gets you running a real app with Postgres in 25 minutes.
Install
# macOS: brew install --cask docker
# Ubuntu: sudo apt install docker.io docker-compose-v2
# Windows: download Docker Desktop
docker --version # should be 27+
Core concepts
| Concept | What it is |
|---|---|
| Image | A read-only template (like a class) |
| Container | A running instance (like an object) |
| Volume | Persistent storage outside the container |
| Network | How containers talk to each other |
| Dockerfile | Recipe to build an image |
Your first container
docker run -d -p 80:80 --name my-nginx nginx
# -d = detached
# -p 80:80 = map host:container
# --name = give it a name
docker ps # list running
docker logs my-nginx
docker stop my-nginx
Your first Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
docker build -t my-app:1.0 .
docker run -d -p 3000:3000 my-app:1.0
docker-compose (multi-container)
# docker-compose.yml
services:
app:
build: .
ports: ["3000:3000"]
depends_on: [db]
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
docker compose up -d
Key takeaways
- Images are templates, containers are instances
- docker-compose is the right tool for multi-service apps
- Volumes are for persistent data