⏱️3 min read · 445 words

Docker is the standard way to build, ship, and run applications in 2026. Every cloud platform — AWS, GCP, Azure — runs Docker containers. This guide covers Docker from first install to multi-container apps with Docker Compose.
📋 Table of Contents
Install Docker
# Ubuntu / Debian
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
newgrp docker
# Verify
docker --version
docker run hello-world
Core Concepts
- Image: Blueprint for a container (read-only)
- Container: Running instance of an image
- Dockerfile: Instructions to build an image
- Registry: Storage for images (Docker Hub, ECR, GCR)
Your First Dockerfile
# Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# Build image
docker build -t myapp:latest .
# Run container
docker run -d -p 8000:8000 --name myapp myapp:latest
# View logs
docker logs myapp
# Stop & remove
docker stop myapp && docker rm myapp
Essential Docker Commands
# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# List images
docker images
# Execute command inside container
docker exec -it myapp /bin/bash
# Copy file from container
docker cp myapp:/app/output.log ./output.log
# Remove all stopped containers + unused images
docker system prune -af
Docker Volumes (Persistent Data)
# Named volume — data persists between container restarts
docker run -d \
-v postgres_data:/var/lib/postgresql/data \
-e POSTGRES_PASSWORD=secret \
--name postgres \
postgres:16
# Bind mount — mount host directory
docker run -d \
-v $(pwd)/data:/app/data \
myapp:latest
Docker Compose — Multi-Container Apps
# docker-compose.yml
services:
web:
build: .
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://postgres:secret@db:5432/mydb
depends_on:
- db
volumes:
- .:/app
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
# Start all services
docker compose up -d
# View logs
docker compose logs -f
# Stop everything
docker compose down
# Rebuild and restart
docker compose up -d --build
Multi-Stage Builds (Smaller Images)
# Stage 1: Build
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json .
RUN npm ci
COPY . .
RUN npm run build
# Stage 2: Production (no dev dependencies)
FROM node:22-alpine AS production
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]
Conclusion
Docker eliminates the “works on my machine” problem. Learn Dockerfile basics, master Docker Compose for local dev, and you will ship consistent apps from laptop to cloud without surprises.
📚 You might also like
🔗 Share this article




✍️ Leave a Comment