Complete Docker Tutorial 2025 - Beginner to Advanced
🐳 What is Docker? Why Learn It in 2025?
Docker is a containerization platform that packages applications with all dependencies into standardized units called containers. In 2025, Docker is not optional - it's fundamental. Here's why:
- ✅ 95% of enterprises use containers in production
- ✅ 80% faster development cycles
- ✅ 70% more efficient resource utilization
📦 Installation (All Platforms)
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install docker.io docker-compose
sudo systemctl start docker
sudo systemctl enable dockerWindows/Mac:
- ✅ Download Docker Desktop from docker.com
- ✅ Includes Docker CLI, Compose, and GUI
- ✅ One-click installation
Verify Installation:
docker --version
docker-compose --version
docker run hello-world🎯 Docker Core Concepts
1. Images vs Containers
- Image: Blueprint/template (read-only)
- Container: Running instance of image (read/write)
2. Dockerfile: Recipe to build images
3. Docker Hub: Registry for public/private images
4. Volumes: Persistent data storage
5. Networks: Communication between containers
🚀 Your First Container
Run a Simple Container:
# Pull and run Nginx
docker run -d -p 8080:80 --name my-nginx nginx
# Access at http://localhost:8080Basic Commands:
docker ps # List running containers
docker ps -a # List all containers
docker images # List images
docker stop <container> # Stop container
docker rm <container> # Remove container
docker rmi <image> # Remove image📝 Dockerfile Mastery
Simple Dockerfile:
# Use official Python image
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Copy requirements first (caching optimization)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Environment variables
ENV PORT=8000
# Expose port
EXPOSE 8000
# Run application
CMD ["python", "app.py"]Multi-Stage Build (Advanced):
# Build stage
FROM node:18 as builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM nginx:alpine
COPY --from=builder /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]🔧 Essential Commands Cheat Sheet
Container Management:
docker run -d -p 80:80 --name web nginx
docker exec -it web bash
docker logs -f web
docker stats
docker inspect webImage Operations:
docker build -t myapp:v1 .
docker tag myapp:v1 username/myapp:latest
docker push username/myapp:latest
docker pull ubuntu:22.04Cleanup:
docker system prune -a # Remove all unused
docker volume prune # Remove unused volumes
docker network prune # Remove unused networks🐳 Docker Compose (Multi-Container Apps)
docker-compose.yml:
version: '3.8'
services:
web:
build: .
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgres://db:5432
depends_on:
- db
volumes:
- ./app:/app
db:
image: postgres:15
environment:
POSTGRES_PASSWORD: secret
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:alpine
volumes:
postgres_data:Compose Commands:
docker-compose up -d
docker-compose down
docker-compose logs -f
docker-compose ps
docker-compose exec web bash🔐 Security Best Practices 2025
1. Use Official Images:
FROM node:18-alpine # Alpine = smaller, more secure2. Non-root User:
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
USER nodejs3. Scan for Vulnerabilities:
docker scan <image-name>4. Secrets Management:
# Use Docker Secrets or environment files
docker run --env-file .env myapp🚀 Advanced Topics
1. Docker Networking:
# Create custom network
docker network create my-network
# Connect containers
docker run --network my-network --name app1 myapp
docker run --network my-network --name app2 myapp2. Docker Volumes:
# Named volume (recommended)
docker volume create app-data
docker run -v app-data:/data myapp
# Bind mount (development)
docker run -v $(pwd):/app myapp3. Docker Registry:
# Run private registry
docker run -d -p 5000:5000 --name registry registry:2
# Push to private registry
docker tag myapp localhost:5000/myapp
docker push localhost:5000/myapp📊 Real-World Examples
1. Node.js Application:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
USER node
CMD ["node", "server.js"]2. Python Django:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "project.wsgi"]3. Java Spring Boot:
FROM openjdk:17-jdk-slim
WORKDIR /app
COPY target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]🔄 CI/CD Integration
GitHub Actions Example:
name: Docker Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker image
run: docker build -t myapp:${{ github.sha }} .
- name: Push to Registry
run: docker push myapp:${{ github.sha }} 🐋 Docker Swarm vs Kubernetes
Docker Swarm (Simpler):
# Initialize swarm
docker swarm init
# Deploy stack
docker stack deploy -c docker-compose.yml myapp
# Scale service
docker service scale myapp_web=5Kubernetes (More Powerful):
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
template:
spec:
containers:
- name: myapp
image: myapp:latest
ports:
- containerPort: 80🎯 Performance Optimization
1. Layer Caching:
# Bad - rebuilds on every code change
COPY . .
RUN npm install
# Good - caches dependencies
COPY package*.json ./
RUN npm install
COPY . .2. Multi-stage Builds:
FROM node:18 as build
WORKDIR /app
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html3. .dockerignore File:
node_modules
.git
*.log
.env
Dockerfile
README.md🔍 Debugging & Troubleshooting
Common Issues:
- "No space left" → Clean up:
docker system prune -a - Permission denied → Use --user flag or fix permissions
- Port already in use → Change port mapping
- Build cache issues → Use --no-cache flag
Debug Commands:
docker logs <container> # View logs
docker exec -it <container> sh # Shell access
docker inspect <container> # Detailed info
docker events # Real-time events📈 Career Impact
With Docker Skills:
- Entry Level: ₹8-12 LPA
- Mid Level: ₹15-25 LPA
- Senior Level: ₹25-45 LPA
- DevOps Engineers: Add ₹5-10 LPA premium
Certifications:
- ✅ Docker Certified Associate (DCA)
- ✅ Kubernetes Certifications (CKA, CKAD)
🎓 Learning Path
Week 1-2: Fundamentals
- ✅ Basic commands
- ✅ Dockerfile creation
- ✅ Simple containers
Week 3-4: Intermediate
- ✅ Docker Compose
- ✅ Networks & volumes
- ✅ Multi-container apps
Week 5-6: Advanced
- ✅ Docker Swarm
- ✅ Security best practices
- ✅ CI/CD integration
Week 7-8: Production
- ✅ Monitoring & logging
- ✅ Performance optimization
- ✅ Real-world deployment
🚀 Next Steps
Practice Projects:
- Containerize a simple web app
- Create microservices with Docker Compose
- Implement CI/CD pipeline
- Deploy to cloud (AWS ECS, Azure ACI, GCP Cloud Run)
Resources:
- Official Docs: docs.docker.com
- Practice: labs.play-with-docker.com
- Community: Docker Discord, Reddit r/docker
✅ Quick Start Checklist
- ☐ Install Docker Desktop
- ☐ Run docker run hello-world
- ☐ Build your first Dockerfile
- ☐ Create docker-compose.yml
- ☐ Push image to Docker Hub
- ☐ Implement volume for persistence
- ☐ Set up custom network
- ☐ Add security best practices
- ☐ Integrate with CI/CD
- ☐ Deploy to production
💡 Pro Tips for 2025
- ✅ Use Alpine images for smaller footprint
- ✅ Implement health checks in Dockerfile
- ✅ Use Docker Scout for vulnerability scanning
- ✅ Learn Docker Compose V3 syntax
- ✅ Practice multi-architecture builds (ARM/x86)
📝 Final Thoughts
Docker in 2025 is not just a tool - it's a fundamental skill for modern software development. Whether you're a developer, DevOps engineer, or system administrator, Docker proficiency opens doors to:
- ✅ Cloud-native development
- ✅ Microservices architecture
- ✅ CI/CD automation
- ✅ High-paying job opportunities
Start today - the learning curve is steep but short, and the rewards are significant. Your first container is just docker run away!
Remember: Practice with real projects, not just tutorials. The best learning happens when you solve real problems.
Ready to Master Docker & DevOps?
Learn Docker, Kubernetes, CI/CD & more with hands-on projects. 85% placement rate, ₹12-18 LPA average salary!
Enroll Now - Next Batch Dec 13