Docker & Kubernetes for Beginners
A practical introduction to containerization and orchestration for modern web applications.
Krishna Phatkure
Software Engineer & Full-Stack Developer
Containerization has revolutionized how we deploy applications. This guide introduces Docker and Kubernetes from the ground up.
What is Docker?
Docker packages your application and its dependencies into a standardized unit called a container. Containers are:
- - Portable: Run anywhere Docker is installed
- Isolated: Don't interfere with other applications
- Lightweight: Share the host OS kernel
Your First Dockerfile
WORKDIR /app
COPY package*.json ./ RUN npm ci --only=production
COPY . .
EXPOSE 3000 CMD ["node", "server.js"] ```
Essential Docker Commands
# Build an image
# Run a container docker run -p 3000:3000 myapp:latest
# List running containers docker ps
# Stop a container
docker stop
What is Kubernetes?
Kubernetes (K8s) orchestrates containers at scale. It handles:
- - Scaling: Run multiple instances of your app
- Load balancing: Distribute traffic automatically
- Self-healing: Restart failed containers
- Rolling updates: Deploy without downtime
Basic Kubernetes Concepts
Pods The smallest deployable unit. Usually contains one container.
Deployments Manage pod replicas and updates.
Services Expose pods to network traffic.
Your First Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:latest
ports:
- containerPort: 3000
Conclusion
Docker and Kubernetes are essential skills for modern developers. Start with Docker, understand containers, then graduate to Kubernetes for production deployments.