Learn the fundamentals of Docker — from installation and your first container to Dockerfiles, Compose, and production best practices.
Docker has revolutionized how we build, ship, and run applications. Instead of worrying about environment differences between development and production, Docker lets you package everything your app needs into a portable container.
Docker is a platform that uses OS-level virtualization to deliver software in packages called containers. Containers are lightweight, standalone, and include everything needed to run a piece of software: code, runtime, libraries, and system tools.
| Feature | Containers | Virtual Machines |
|---|---|---|
| Startup time | Seconds | Minutes |
| Size | Megabytes | Gigabytes |
| Isolation | Process-level | Full OS |
| Performance | Near-native | Overhead from hypervisor |
On macOS or Windows, install Docker Desktop from docker.com. On Linux:
# Ubuntu / Debian
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
# Add your user to the docker group
sudo usermod -aG docker $USER
# Pull and run the official Nginx image
docker run -d -p 8080:80 --name my-nginx nginx
# Verify it's running
docker ps
# Check logs
docker logs my-nginx
# Stop and remove
docker stop my-nginx
docker rm my-nginx
A Dockerfile defines how to build your image. Here's one for a Node.js app:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
Build and run it:
docker build -t my-node-app .
docker run -d -p 3000:3000 my-node-app
docker images — list local imagesdocker ps -a — list all containers (including stopped)docker exec -it <container> sh — shell into a running containerdocker volume ls — list volumes for persistent datadocker network ls — list networksFor multi-container setups, use Docker Compose:
version: "3.9"
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Run with docker compose up -d.
.dockerignore to exclude unnecessary filesnode:20-alpine, not node:latest)Docker is the foundation of modern DevOps. Master these basics and you're ready to tackle orchestration with Kubernetes.
Get more DevOps insights delivered to your inbox.
Subscribe to get an email when a new blog post is published. Skip anytime.
No spam, unsubscribe anytime.
1 comment
Sign in to join the conversation.
This is exactly what I needed to get started with Docker. The Compose example is really helpful!
Glad it helped! Multi-stage builds are a game-changer for keeping images small.