Skip to content
Live

Docker for Developers: A Practical Guide

Stop the 'works on my machine' problem forever. Learn Docker from containers to Compose to production-ready multi-stage builds.

By Soren Lindqvist12 min read

Why Docker Matters

Every developer has said "it works on my machine." Docker eliminates that phrase by packaging your application with everything it needs to run — OS libraries, runtime, dependencies — into a portable container.

Your First Dockerfile

FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

EXPOSE 3000
CMD ["node", "server.js"]

Multi-Stage Builds

Dramatically reduce image size by separating build and runtime:

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

EXPOSE 3000
CMD ["npm", "start"]

Docker Compose for Local Dev

version: "3.9"
services:
  app:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - /app/node_modules
    environment:
      - DATABASE_URL=postgres://user:pass@db:5432/mydb
    depends_on:
      - db

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

Essential Commands

docker build -t myapp .          # Build image
docker run -p 3000:3000 myapp    # Run container
docker compose up -d             # Start all services
docker compose logs -f app       # Follow logs
docker exec -it myapp sh         # Shell into container

Docker is the single best investment you can make in your development workflow.

Share

Written by

Soren Lindqvist

Engineer. Ships the TypeScript, Docker, and database pieces, usually after breaking them in production first.

git

Git Workflows for Modern Teams

From trunk-based development to GitFlow — choose the right branching strategy for your team size, release cadence, and deployment model.

Soren Lindqvist8 min read
programming

How to Contribute to Open Source

Your first open source contribution doesn't have to be a major feature. A practical guide to finding projects, making meaningful contributions, and building your reputation.

Amara Osei7 min read
css

Advanced Tailwind CSS Patterns

Go beyond utility classes. Learn Tailwind's plugin system, custom design tokens, component extraction, and the patterns that scale to large codebases.

Soren Lindqvist9 min read