From 735f676328804a0c76e28be875d344d8daabb39e Mon Sep 17 00:00:00 2001 From: Richajaishwal0 Date: Fri, 28 Nov 2025 16:38:28 +0530 Subject: [PATCH] added sidebar for docker and changed its content --- docs/Docker/docker-commands.md | 561 +++++++++++++ docs/Docker/docker-compose-advanced.md | 660 ++++++++++++++++ docs/Docker/docker-compose.md | 357 +++++++++ docs/Docker/dockerfile-guide.md | 747 ++++++++++++++++++ docs/Docker/intro.md | 108 ++- docs/Docker/setup-environment.md | 315 ++++++++ sidebars.ts | 23 + src/theme/DocSidebarItem/Category/index.tsx | 5 + .../DocSidebarItem/Category/styles.module.css | 10 + 9 files changed, 2745 insertions(+), 41 deletions(-) create mode 100644 docs/Docker/docker-commands.md create mode 100644 docs/Docker/docker-compose-advanced.md create mode 100644 docs/Docker/docker-compose.md create mode 100644 docs/Docker/dockerfile-guide.md create mode 100644 docs/Docker/setup-environment.md diff --git a/docs/Docker/docker-commands.md b/docs/Docker/docker-commands.md new file mode 100644 index 00000000..54720ddc --- /dev/null +++ b/docs/Docker/docker-commands.md @@ -0,0 +1,561 @@ +--- +id: docker-commands +title: Essential Docker Commands +sidebar_label: Docker Commands +sidebar_position: 3 +tags: + [ + docker, + commands, + cli, + docker-run, + docker-build + ] +description: Master essential Docker commands for container and image management. Complete guide to Docker CLI with practical examples and best practices. +--- + +# Essential Docker Commands + +Master the Docker command-line interface (CLI) to effectively manage containers, images, networks, and volumes. + +## Container Management Commands + +### Running Containers + +**Basic Run Command** +```bash +# Run a container +docker run [OPTIONS] IMAGE [COMMAND] [ARG...] + +# Examples +docker run hello-world +docker run -it ubuntu bash +docker run -d nginx +docker run -p 8080:80 nginx +``` + +**Common Run Options** +```bash +# Run in detached mode (background) +docker run -d nginx + +# Interactive mode with terminal +docker run -it ubuntu bash + +# Port mapping (host:container) +docker run -p 8080:80 nginx + +# Environment variables +docker run -e NODE_ENV=production node-app + +# Volume mounting +docker run -v /host/path:/container/path nginx + +# Name your container +docker run --name my-nginx nginx + +# Remove container after exit +docker run --rm ubuntu echo "Hello World" + +# Restart policy +docker run --restart unless-stopped nginx +``` + +### Container Lifecycle + +**Start, Stop, Restart** +```bash +# Start a stopped container +docker start container-name + +# Stop a running container +docker stop container-name + +# Restart a container +docker restart container-name + +# Pause/unpause a container +docker pause container-name +docker unpause container-name + +# Kill a container (force stop) +docker kill container-name +``` + +**Container Information** +```bash +# List running containers +docker ps + +# List all containers (including stopped) +docker ps -a + +# Show container details +docker inspect container-name + +# View container logs +docker logs container-name +docker logs -f container-name # Follow logs + +# Show running processes in container +docker top container-name + +# Display resource usage statistics +docker stats container-name +``` + +### Executing Commands in Containers + +```bash +# Execute command in running container +docker exec container-name command + +# Interactive shell in running container +docker exec -it container-name bash +docker exec -it container-name sh + +# Execute as specific user +docker exec -u root -it container-name bash + +# Execute with environment variables +docker exec -e VAR=value container-name command +``` + +### Container Cleanup + +```bash +# Remove a container +docker rm container-name + +# Remove running container (force) +docker rm -f container-name + +# Remove multiple containers +docker rm container1 container2 + +# Remove all stopped containers +docker container prune + +# Remove all containers (dangerous!) +docker rm -f $(docker ps -aq) +``` + +--- + +## Image Management Commands + +### Building Images + +**Build from Dockerfile** +```bash +# Build image from current directory +docker build . + +# Build with tag +docker build -t my-app:1.0 . + +# Build with custom Dockerfile +docker build -f Dockerfile.prod -t my-app:prod . + +# Build with build arguments +docker build --build-arg VERSION=1.0 -t my-app . + +# Build without cache +docker build --no-cache -t my-app . +``` + +### Image Operations + +**Pulling and Pushing** +```bash +# Pull image from registry +docker pull nginx +docker pull nginx:1.21-alpine + +# Push image to registry +docker push my-registry.com/my-app:1.0 + +# Tag an image +docker tag my-app:1.0 my-registry.com/my-app:1.0 +``` + +**Image Information** +```bash +# List images +docker images +docker image ls + +# Show image details +docker inspect image-name + +# Show image history (layers) +docker history image-name + +# Show image size and usage +docker system df +``` + +### Image Cleanup + +```bash +# Remove an image +docker rmi image-name + +# Remove multiple images +docker rmi image1 image2 + +# Remove unused images +docker image prune + +# Remove all unused images (including tagged) +docker image prune -a + +# Remove images by filter +docker image prune --filter "until=24h" +``` + +--- + +## Network Management + +### Network Operations + +```bash +# List networks +docker network ls + +# Create a network +docker network create my-network +docker network create --driver bridge my-bridge + +# Connect container to network +docker network connect my-network container-name + +# Disconnect container from network +docker network disconnect my-network container-name + +# Inspect network +docker network inspect my-network + +# Remove network +docker network rm my-network + +# Remove unused networks +docker network prune +``` + +### Network Types + +```bash +# Bridge network (default) +docker network create --driver bridge my-bridge + +# Host network (Linux only) +docker run --network host nginx + +# None network (no networking) +docker run --network none alpine + +# Custom bridge with subnet +docker network create --driver bridge --subnet=172.20.0.0/16 my-custom-bridge +``` + +--- + +## Volume Management + +### Volume Operations + +```bash +# List volumes +docker volume ls + +# Create a volume +docker volume create my-volume + +# Inspect volume +docker volume inspect my-volume + +# Remove volume +docker volume rm my-volume + +# Remove unused volumes +docker volume prune + +# Remove all volumes (dangerous!) +docker volume rm $(docker volume ls -q) +``` + +### Volume Usage + +```bash +# Named volume +docker run -v my-volume:/app/data nginx + +# Bind mount +docker run -v /host/path:/container/path nginx + +# Read-only mount +docker run -v /host/path:/container/path:ro nginx + +# Temporary filesystem (tmpfs) +docker run --tmpfs /tmp nginx +``` + +--- + +## System Management + +### System Information + +```bash +# Show Docker system information +docker system info + +# Show disk usage +docker system df + +# Show detailed disk usage +docker system df -v + +# Show Docker version +docker version + +# Show events in real-time +docker system events +``` + +### System Cleanup + +```bash +# Remove all unused objects +docker system prune + +# Remove all unused objects including volumes +docker system prune --volumes + +# Remove all unused objects including unused images +docker system prune -a + +# Remove objects older than specified time +docker system prune --filter "until=24h" +``` + +--- + +## Docker Compose Commands + +### Basic Compose Operations + +```bash +# Start services +docker-compose up + +# Start in detached mode +docker-compose up -d + +# Build and start +docker-compose up --build + +# Start specific service +docker-compose up web + +# Scale services +docker-compose up --scale web=3 + +# Stop services +docker-compose down + +# Stop and remove volumes +docker-compose down -v + +# Stop and remove images +docker-compose down --rmi all +``` + +### Compose Management + +```bash +# View running services +docker-compose ps + +# View logs +docker-compose logs +docker-compose logs -f web + +# Execute command in service +docker-compose exec web bash + +# Run one-off command +docker-compose run web python manage.py migrate + +# Restart services +docker-compose restart + +# Pull latest images +docker-compose pull +``` + +--- + +## Advanced Commands + +### Container Inspection + +```bash +# Copy files to/from container +docker cp file.txt container:/app/ +docker cp container:/app/logs ./ + +# Export container as tar +docker export container-name > container.tar + +# Import tar as image +docker import container.tar my-image:latest + +# Save image as tar +docker save my-image:latest > image.tar + +# Load image from tar +docker load < image.tar +``` + +### Resource Management + +```bash +# Run with resource limits +docker run -m 512m --cpus="1.5" nginx + +# Update container resources +docker update --memory 1g --cpus="2" container-name + +# Set restart policy +docker update --restart unless-stopped container-name +``` + +### Security Commands + +```bash +# Run as specific user +docker run -u 1000:1000 nginx + +# Run with read-only filesystem +docker run --read-only nginx + +# Add/drop capabilities +docker run --cap-add NET_ADMIN nginx +docker run --cap-drop ALL nginx + +# Set security options +docker run --security-opt no-new-privileges nginx +``` + +--- + +## Command Cheat Sheet + +### Most Used Commands + +| Command | Description | +|---------|-------------| +| `docker run` | Create and start container | +| `docker ps` | List running containers | +| `docker images` | List images | +| `docker build` | Build image from Dockerfile | +| `docker pull` | Download image | +| `docker push` | Upload image | +| `docker exec` | Execute command in container | +| `docker logs` | View container logs | +| `docker stop` | Stop container | +| `docker rm` | Remove container | +| `docker rmi` | Remove image | + +### Quick Cleanup + +```bash +# Clean everything +docker system prune -a --volumes + +# Clean containers only +docker container prune + +# Clean images only +docker image prune -a + +# Clean networks only +docker network prune + +# Clean volumes only +docker volume prune +``` + +--- + +## Best Practices + +### Command Tips + +1. **Use specific tags** - Avoid `:latest` in production +2. **Name your containers** - Use `--name` for easier management +3. **Use labels** - Add metadata with `--label` +4. **Limit resources** - Set memory and CPU limits +5. **Use health checks** - Monitor container health +6. **Clean up regularly** - Remove unused objects + +### Security Tips + +```bash +# Don't run as root +docker run -u 1000:1000 my-app + +# Use read-only filesystem when possible +docker run --read-only my-app + +# Drop unnecessary capabilities +docker run --cap-drop ALL --cap-add NET_BIND_SERVICE my-app + +# Use security profiles +docker run --security-opt apparmor:my-profile my-app +``` + +--- + +## Troubleshooting Commands + +### Debugging Containers + +```bash +# Check why container exited +docker ps -a +docker logs container-name + +# Inspect container configuration +docker inspect container-name + +# Check resource usage +docker stats container-name + +# Access container filesystem +docker exec -it container-name sh + +# Check network connectivity +docker exec container-name ping google.com +``` + +### Performance Monitoring + +```bash +# Real-time resource usage +docker stats + +# Container processes +docker top container-name + +# System events +docker system events + +# Disk usage breakdown +docker system df -v +``` + +Ready to master Docker? Practice these commands and move on to learning Dockerfile creation! πŸš€ \ No newline at end of file diff --git a/docs/Docker/docker-compose-advanced.md b/docs/Docker/docker-compose-advanced.md new file mode 100644 index 00000000..dadb5d43 --- /dev/null +++ b/docs/Docker/docker-compose-advanced.md @@ -0,0 +1,660 @@ +--- +id: docker-compose-advanced +title: Docker Compose Advanced +sidebar_label: 2. Advanced +sidebar_position: 6 +tags: + [ + docker, + docker-compose, + production, + microservices, + scaling + ] +description: Advanced Docker Compose features for production - microservices, scaling, security, monitoring, and complex multi-environment setups. +--- + +# Docker Compose Advanced + +Master advanced Docker Compose features for production environments, including microservices architecture, scaling, security, and complex configurations. + +## Microservices Architecture + +Build scalable microservices with Docker Compose for complex distributed applications. + +### Complete Microservices Stack + +```yaml +version: '3.8' + +services: + # API Gateway + gateway: + build: ./gateway + ports: + - "8080:8080" + environment: + - USER_SERVICE_URL=http://user-service:3001 + - ORDER_SERVICE_URL=http://order-service:3002 + - PRODUCT_SERVICE_URL=http://product-service:3003 + depends_on: + - user-service + - order-service + - product-service + networks: + - microservices + + # User Service + user-service: + build: ./services/user + environment: + - DATABASE_URL=postgresql://user:password@user-db:5432/users + depends_on: + user-db: + condition: service_healthy + networks: + - microservices + - user-network + + # Order Service + order-service: + build: ./services/order + environment: + - DATABASE_URL=postgresql://user:password@order-db:5432/orders + - RABBITMQ_URL=amqp://rabbitmq:5672 + depends_on: + order-db: + condition: service_healthy + rabbitmq: + condition: service_started + networks: + - microservices + - order-network + + # Product Service + product-service: + build: ./services/product + environment: + - MONGODB_URL=mongodb://product-db:27017/products + depends_on: + - product-db + networks: + - microservices + - product-network + + # Databases + user-db: + image: postgres:13-alpine + environment: + POSTGRES_DB: users + POSTGRES_USER: user + POSTGRES_PASSWORD: password + volumes: + - user-db-data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U user -d users"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - user-network + + order-db: + image: postgres:13-alpine + environment: + POSTGRES_DB: orders + POSTGRES_USER: user + POSTGRES_PASSWORD: password + volumes: + - order-db-data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U user -d orders"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - order-network + + product-db: + image: mongo:5 + volumes: + - product-db-data:/data/db + networks: + - product-network + + # Message Queue + rabbitmq: + image: rabbitmq:3-management-alpine + ports: + - "15672:15672" # Management UI + environment: + RABBITMQ_DEFAULT_USER: admin + RABBITMQ_DEFAULT_PASS: admin + volumes: + - rabbitmq-data:/var/lib/rabbitmq + networks: + - microservices + +volumes: + user-db-data: + order-db-data: + product-db-data: + rabbitmq-data: + +networks: + microservices: + driver: bridge + user-network: + driver: bridge + order-network: + driver: bridge + product-network: + driver: bridge +``` + +--- + +## Advanced Networks + +Configure complex networking scenarios for production environments. + +### Custom Network Configuration + +```yaml +version: '3.8' + +services: + frontend: + image: nginx + networks: + - frontend-network + + backend: + image: node:alpine + networks: + - frontend-network + - backend-network + + database: + image: postgres + networks: + - backend-network + +networks: + frontend-network: + driver: bridge + ipam: + config: + - subnet: 172.20.0.0/16 + backend-network: + driver: bridge + internal: true # No external access +``` + +### External Networks + +```yaml +version: '3.8' + +services: + app: + image: my-app + networks: + - existing-network + - new-network + +networks: + existing-network: + external: true + new-network: + driver: bridge +``` + +--- + +## Production Volumes + +Manage persistent data storage for production workloads. + +### Named and External Volumes + +```yaml +version: '3.8' + +services: + database: + image: postgres + volumes: + - postgres-data:/var/lib/postgresql/data + - backup-volume:/backups + - ./config:/etc/postgresql/conf.d:ro + +volumes: + postgres-data: + driver: local + driver_opts: + type: none + o: bind + device: /opt/postgres-data + backup-volume: + external: true +``` + +### Volume Drivers + +```yaml +version: '3.8' + +services: + app: + image: my-app + volumes: + - nfs-data:/data + +volumes: + nfs-data: + driver: local + driver_opts: + type: nfs + o: addr=192.168.1.100,rw + device: ":/path/to/dir" +``` + +--- + +## Resource Management + +Control resource allocation and scaling for optimal performance. + +### Resource Limits + +```yaml +version: '3.8' + +services: + web: + image: nginx + deploy: + resources: + limits: + cpus: '0.5' + memory: 512M + reservations: + cpus: '0.25' + memory: 256M + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s +``` + +### Scaling Services + +```yaml +version: '3.8' + +services: + web: + image: nginx + deploy: + replicas: 3 + update_config: + parallelism: 1 + delay: 10s + restart_policy: + condition: on-failure +``` + +--- + +## Security Configuration + +Implement security best practices for production deployments. + +### Security Best Practices + +```yaml +version: '3.8' + +services: + app: + image: my-app + user: "1000:1000" # Non-root user + read_only: true # Read-only filesystem + tmpfs: + - /tmp + - /var/run + cap_drop: + - ALL + cap_add: + - NET_BIND_SERVICE + security_opt: + - no-new-privileges:true + sysctls: + - net.core.somaxconn=1024 +``` + +### Secrets Management + +```yaml +version: '3.8' + +services: + app: + image: my-app + secrets: + - db_password + - api_key + environment: + - DB_PASSWORD_FILE=/run/secrets/db_password + +secrets: + db_password: + file: ./secrets/db_password.txt + api_key: + external: true +``` + +--- + +## Health Checks & Monitoring + +Ensure application reliability with comprehensive monitoring. + +### Advanced Health Checks + +```yaml +version: '3.8' + +services: + web: + image: nginx + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s + depends_on: + database: + condition: service_healthy + + database: + image: postgres:13 + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s +``` + +### Monitoring Stack + +```yaml +version: '3.8' + +services: + app: + build: . + ports: + - "3000:3000" + networks: + - monitoring + + prometheus: + image: prom/prometheus + ports: + - "9090:9090" + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + - prometheus-data:/prometheus + networks: + - monitoring + + grafana: + image: grafana/grafana + ports: + - "3001:3000" + environment: + - GF_SECURITY_ADMIN_PASSWORD=admin + volumes: + - grafana-data:/var/lib/grafana + networks: + - monitoring + +volumes: + prometheus-data: + grafana-data: + +networks: + monitoring: +``` + +--- + +## Multi-Environment Setup + +Manage different environments with compose file overrides. + +### Environment-Specific Files + +**docker-compose.yml** (Base Configuration) +```yaml +version: '3.8' + +services: + app: + build: . + environment: + - NODE_ENV=${NODE_ENV} + volumes: + - ./src:/app/src +``` + +**docker-compose.prod.yml** (Production Override) +```yaml +version: '3.8' + +services: + app: + build: + target: production + volumes: [] # Remove dev volumes + deploy: + resources: + limits: + memory: 1G + reservations: + memory: 512M +``` + +**docker-compose.dev.yml** (Development Override) +```yaml +version: '3.8' + +services: + app: + build: + target: development + volumes: + - ./src:/app/src + - /app/node_modules + ports: + - "3000:3000" +``` + +### Usage Commands + +```bash +# Development environment +docker-compose -f docker-compose.yml -f docker-compose.dev.yml up + +# Production environment +docker-compose -f docker-compose.yml -f docker-compose.prod.yml up + +# Testing environment +docker-compose -f docker-compose.yml -f docker-compose.test.yml up +``` + +--- + +## Advanced Configurations + +Leverage advanced Docker Compose features for complex scenarios. + +### Custom Build Context + +```yaml +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile.prod + args: + - NODE_VERSION=18 + - BUILD_DATE=${BUILD_DATE} + target: production + cache_from: + - my-app:cache +``` + +### Init Containers + +```yaml +version: '3.8' + +services: + # Database migration container + migrate: + image: my-app:latest + command: ["python", "manage.py", "migrate"] + depends_on: + database: + condition: service_healthy + restart: "no" + + # Main application + app: + image: my-app:latest + depends_on: + - migrate + ports: + - "8000:8000" +``` + +--- + +## Troubleshooting & Debugging + +Debug and resolve common Docker Compose issues. + +### Debug Configuration + +```yaml +version: '3.8' + +services: + app: + image: my-app + environment: + - DEBUG=true + - LOG_LEVEL=debug + volumes: + - ./logs:/app/logs + ports: + - "9229:9229" # Debug port +``` + +### Common Issues Solutions + +#### Service Discovery Problems +```bash +# Check network configuration +docker-compose config + +# Test connectivity +docker-compose exec web ping database +docker-compose exec web nslookup database +``` + +#### Volume Permission Issues +```yaml +services: + app: + image: my-app + user: "${UID}:${GID}" + volumes: + - ./data:/app/data +``` + +#### Resource Constraints +```yaml +services: + app: + image: my-app + deploy: + resources: + limits: + memory: 2G + reservations: + memory: 1G +``` + +--- + +## Best Practices + +Follow these guidelines for maintainable Docker Compose configurations. + +### File Organization + +``` +project/ +β”œβ”€β”€ docker-compose.yml +β”œβ”€β”€ docker-compose.override.yml +β”œβ”€β”€ docker-compose.prod.yml +β”œβ”€β”€ docker-compose.dev.yml +β”œβ”€β”€ .env +β”œβ”€β”€ .env.example +β”œβ”€β”€ services/ +β”‚ β”œβ”€β”€ web/ +β”‚ β”‚ └── Dockerfile +β”‚ └── api/ +β”‚ └── Dockerfile +β”œβ”€β”€ config/ +β”‚ β”œβ”€β”€ nginx.conf +β”‚ └── prometheus.yml +└── secrets/ + └── .gitkeep +``` + +### Version Control + +```gitignore +# .gitignore +.env +.env.local +docker-compose.override.yml +volumes/ +logs/ +secrets/*.txt +``` + +### Production Checklist + +- **Image Tags**: Use specific versions instead of `latest` +- **Resource Limits**: Set CPU and memory constraints +- **Health Checks**: Configure service health monitoring +- **Secrets**: Use Docker secrets for sensitive data +- **Security**: Run containers as non-root users +- **Logging**: Enable centralized log collection +- **Monitoring**: Set up application and infrastructure monitoring +- **Backups**: Configure automated backup strategies +- **Networks**: Use external networks and volumes for persistence +- **Testing**: Implement disaster recovery procedures + +Ready to deploy production-grade multi-container applications with Docker Compose advanced patterns! \ No newline at end of file diff --git a/docs/Docker/docker-compose.md b/docs/Docker/docker-compose.md new file mode 100644 index 00000000..f1035149 --- /dev/null +++ b/docs/Docker/docker-compose.md @@ -0,0 +1,357 @@ +--- +id: docker-compose +title: Docker Compose Basics +sidebar_label: 1. Basics +sidebar_position: 5 +tags: + [ + docker, + docker-compose, + multi-container, + basics + ] +description: Learn Docker Compose fundamentals - basic structure, service configuration, and simple multi-container applications. +--- + +# Docker Compose Basics + +Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services, networks, and volumes. + +## What is Docker Compose? + +Docker Compose allows you to: + +- **Define** multi-container applications in a single file +- **Start** all services with one command +- **Scale** services up or down easily +- **Manage** application lifecycle +- **Share** configurations with your team + +--- + +## Basic docker-compose.yml Structure + +Understanding the fundamental structure of Docker Compose files. + +### Simple Example + +```yaml +version: '3.8' + +services: + web: + image: nginx:alpine + ports: + - "8080:80" + + database: + image: postgres:13 + environment: + POSTGRES_PASSWORD: mypassword +``` + +### Complete Structure + +```yaml +version: '3.8' + +services: + # Service definitions + +networks: + # Network definitions + +volumes: + # Volume definitions + +configs: + # Config definitions (Swarm mode) + +secrets: + # Secret definitions (Swarm mode) +``` + +--- + +## Service Configuration + +Configure individual services within your Docker Compose application. + +### Basic Service Options + +```yaml +services: + web: + # Use existing image + image: nginx:alpine + + # Build from Dockerfile + build: . + + # Build with context and dockerfile + build: + context: . + dockerfile: Dockerfile.prod + args: + - NODE_ENV=production + + # Container name + container_name: my-web-app + + # Restart policy + restart: unless-stopped + + # Port mapping + ports: + - "8080:80" + - "443:443" + + # Environment variables + environment: + - NODE_ENV=production + - DEBUG=false + + # Environment file + env_file: + - .env + - .env.prod +``` + +### Advanced Service Options + +```yaml +services: + app: + image: my-app:latest + + # Dependencies + depends_on: + - database + - redis + + # Health check dependency + depends_on: + database: + condition: service_healthy + + # Volume mounts + volumes: + - ./src:/app/src + - app-data:/app/data + - /host/logs:/app/logs:ro + + # Networks + networks: + - frontend + - backend + + # Health check + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s +``` + +--- + +## Simple Examples + +Practical examples to get started with Docker Compose. + +### Web Application Stack + +```yaml +version: '3.8' + +services: + # Frontend + frontend: + build: ./frontend + ports: + - "3000:3000" + environment: + - REACT_APP_API_URL=http://localhost:5000 + depends_on: + - backend + + # Backend API + backend: + build: ./backend + ports: + - "5000:5000" + environment: + - DATABASE_URL=postgresql://user:password@database:5432/myapp + depends_on: + - database + + # Database + database: + image: postgres:13-alpine + environment: + POSTGRES_DB: myapp + POSTGRES_USER: user + POSTGRES_PASSWORD: password + volumes: + - postgres-data:/var/lib/postgresql/data + +volumes: + postgres-data: +``` + +### WordPress with MySQL + +```yaml +version: '3.8' + +services: + wordpress: + image: wordpress:latest + ports: + - "8080:80" + environment: + WORDPRESS_DB_HOST: mysql:3306 + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress_password + WORDPRESS_DB_NAME: wordpress + volumes: + - wordpress-data:/var/www/html + depends_on: + - mysql + + mysql: + image: mysql:8.0 + environment: + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress_password + MYSQL_ROOT_PASSWORD: root_password + volumes: + - mysql-data:/var/lib/mysql + +volumes: + wordpress-data: + mysql-data: +``` + +--- + +## Networks and Volumes + +Manage container networking and data persistence. + +### Basic Networks + +```yaml +version: '3.8' + +services: + web: + image: nginx + networks: + - frontend + + api: + image: node:alpine + networks: + - frontend + - backend + + database: + image: postgres + networks: + - backend + +networks: + frontend: + backend: +``` + +### Basic Volumes + +```yaml +version: '3.8' + +services: + database: + image: postgres:13 + volumes: + - db-data:/var/lib/postgresql/data + - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro + environment: + POSTGRES_PASSWORD: password + +volumes: + db-data: +``` + +--- + +## Environment Variables + +Manage configuration through environment variables. + +### Using .env Files + +**docker-compose.yml** +```yaml +version: '3.8' + +services: + app: + image: my-app:${TAG:-latest} + environment: + - NODE_ENV=${NODE_ENV:-development} + - DATABASE_URL=${DATABASE_URL} + env_file: + - .env +``` + +**.env file** +```bash +TAG=v1.0.0 +NODE_ENV=production +DATABASE_URL=postgresql://user:pass@db:5432/myapp +``` + +--- + +## Basic Commands + +Essential Docker Compose commands for daily operations. + +```bash +# Start services +docker-compose up + +# Start in background +docker-compose up -d + +# Stop services +docker-compose down + +# View logs +docker-compose logs + +# Execute commands +docker-compose exec web bash + +# View running services +docker-compose ps + +# Scale services +docker-compose up --scale web=3 +``` + +--- + +## Next Steps + +Now that you understand Docker Compose basics: + +1. **Practice with Examples** - Try the provided examples in your projects +2. **Learn Advanced Features** - Explore production configurations and scaling +3. **Master Complex Architectures** - Build microservices and multi-environment setups + +Ready for advanced topics? Check out [Docker Compose Advanced](./docker-compose-advanced.md) for production-ready configurations! \ No newline at end of file diff --git a/docs/Docker/dockerfile-guide.md b/docs/Docker/dockerfile-guide.md new file mode 100644 index 00000000..ff7300a3 --- /dev/null +++ b/docs/Docker/dockerfile-guide.md @@ -0,0 +1,747 @@ +--- +id: dockerfile-guide +title: Dockerfile Complete Guide +sidebar_label: Dockerfile Guide +sidebar_position: 4 +tags: + [ + docker, + dockerfile, + image-building, + best-practices + ] +description: Complete guide to writing Dockerfiles. Learn all Dockerfile instructions, best practices, multi-stage builds, and optimization techniques. +--- + +# Dockerfile Complete Guide + +A Dockerfile is a text file containing instructions to build Docker images. Master Dockerfile creation to build efficient, secure, and maintainable container images. + +## What is a Dockerfile? + +A Dockerfile is a script containing a series of instructions used to build a Docker image automatically. Each instruction creates a new layer in the image. + +**Basic Structure:** +```dockerfile +# Comment +INSTRUCTION arguments +``` + +--- + +## Dockerfile Instructions + +### FROM - Base Image + +**Sets the base image for subsequent instructions** + +```dockerfile +# Use official image +FROM node:18-alpine + +# Use specific version +FROM python:3.11-slim + +# Use scratch (empty image) +FROM scratch + +# Multi-stage build +FROM node:18-alpine AS builder +``` + +**Best Practices:** +- Use official images when possible +- Specify exact versions for reproducibility +- Use minimal base images (alpine, slim) + +### WORKDIR - Working Directory + +**Sets the working directory for subsequent instructions** + +```dockerfile +# Set working directory +WORKDIR /app + +# Creates directory if it doesn't exist +WORKDIR /app/src + +# Use absolute paths +WORKDIR /usr/src/app +``` + +### COPY vs ADD + +**COPY - Copy files/directories** +```dockerfile +# Copy single file +COPY package.json . + +# Copy directory +COPY src/ ./src/ + +# Copy with ownership +COPY --chown=node:node package.json . + +# Copy from build stage +COPY --from=builder /app/dist ./dist +``` + +**ADD - Copy with additional features** +```dockerfile +# Copy and extract tar +ADD app.tar.gz /app/ + +# Download from URL (not recommended) +ADD https://example.com/file.tar.gz /app/ + +# Copy files (same as COPY) +ADD package.json . +``` + +**When to use:** +- **COPY**: For simple file copying (recommended) +- **ADD**: Only when you need auto-extraction or URL download + +### RUN - Execute Commands + +**Execute commands during image build** + +```dockerfile +# Single command +RUN npm install + +# Multiple commands (inefficient) +RUN apt-get update +RUN apt-get install -y curl +RUN apt-get clean + +# Multiple commands (efficient) +RUN apt-get update && \ + apt-get install -y curl && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Using arrays (exec form) +RUN ["npm", "install"] +``` + +### CMD - Default Command + +**Specify default command when container starts** + +```dockerfile +# Shell form +CMD npm start + +# Exec form (recommended) +CMD ["npm", "start"] + +# With parameters +CMD ["node", "server.js"] + +# Can be overridden at runtime +# docker run my-app python app.py +``` + +### ENTRYPOINT - Entry Point + +**Configure container as executable** + +```dockerfile +# Exec form (recommended) +ENTRYPOINT ["python", "app.py"] + +# Shell form +ENTRYPOINT python app.py + +# Combined with CMD +ENTRYPOINT ["python"] +CMD ["app.py"] + +# Runtime: docker run my-app script.py +# Executes: python script.py +``` + +**ENTRYPOINT vs CMD:** +- **ENTRYPOINT**: Cannot be overridden, always executes +- **CMD**: Can be overridden by runtime arguments +- **Both**: ENTRYPOINT + CMD for flexible defaults + +### ENV - Environment Variables + +**Set environment variables** + +```dockerfile +# Single variable +ENV NODE_ENV=production + +# Multiple variables +ENV NODE_ENV=production \ + PORT=3000 \ + DEBUG=false + +# Using in other instructions +ENV APP_HOME=/app +WORKDIR $APP_HOME +``` + +### ARG - Build Arguments + +**Define build-time variables** + +```dockerfile +# Define argument +ARG VERSION=1.0 +ARG BUILD_DATE + +# Use in instructions +FROM node:${VERSION}-alpine +LABEL build-date=${BUILD_DATE} + +# Build with arguments +# docker build --build-arg VERSION=2.0 --build-arg BUILD_DATE=$(date) . +``` + +### EXPOSE - Document Ports + +**Document which ports the container listens on** + +```dockerfile +# Single port +EXPOSE 3000 + +# Multiple ports +EXPOSE 3000 8080 + +# With protocol +EXPOSE 3000/tcp +EXPOSE 53/udp + +# Note: EXPOSE doesn't publish ports +# Use -p flag: docker run -p 3000:3000 my-app +``` + +### VOLUME - Mount Points + +**Create mount points for external volumes** + +```dockerfile +# Single volume +VOLUME /data + +# Multiple volumes +VOLUME ["/data", "/logs"] + +# Best practice: Use at runtime instead +# docker run -v my-data:/data my-app +``` + +### USER - Switch User + +**Set user for subsequent instructions** + +```dockerfile +# Create user and switch +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 +USER nextjs + +# Switch to existing user +USER node + +# Use numeric ID +USER 1001:1001 +``` + +### LABEL - Metadata + +**Add metadata to image** + +```dockerfile +# Single label +LABEL version="1.0" + +# Multiple labels +LABEL version="1.0" \ + description="My application" \ + maintainer="developer@example.com" + +# Standard labels +LABEL org.opencontainers.image.title="My App" +LABEL org.opencontainers.image.version="1.0.0" +``` + +--- + +## Multi-Stage Builds + +**Build efficient images by using multiple FROM statements** + +### Basic Multi-Stage Example + +```dockerfile +# Build stage +FROM node:18-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm ci --only=production + +# Production stage +FROM node:18-alpine AS production +WORKDIR /app +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 +COPY --from=builder /app/node_modules ./node_modules +COPY . . +USER nextjs +EXPOSE 3000 +CMD ["npm", "start"] +``` + +### Advanced Multi-Stage Example + +```dockerfile +# Base stage with common dependencies +FROM node:18-alpine AS base +WORKDIR /app +COPY package*.json ./ + +# Development dependencies +FROM base AS dev-deps +RUN npm ci + +# Production dependencies +FROM base AS prod-deps +RUN npm ci --only=production + +# Build stage +FROM dev-deps AS build +COPY . . +RUN npm run build + +# Test stage +FROM dev-deps AS test +COPY . . +RUN npm test + +# Production stage +FROM node:18-alpine AS production +WORKDIR /app +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 +COPY --from=prod-deps /app/node_modules ./node_modules +COPY --from=build /app/dist ./dist +USER nextjs +EXPOSE 3000 +CMD ["node", "dist/server.js"] +``` + +### Build Specific Stage + +```bash +# Build only test stage +docker build --target test -t my-app:test . + +# Build production stage +docker build --target production -t my-app:prod . +``` + +--- + +## Best Practices + +### Image Size Optimization + +**1. Use Minimal Base Images** +```dockerfile +# Good: Alpine-based images +FROM node:18-alpine +FROM python:3.11-alpine + +# Better: Distroless images +FROM gcr.io/distroless/nodejs18-debian11 + +# Best: Scratch for static binaries +FROM scratch +``` + +**2. Minimize Layers** +```dockerfile +# Bad: Multiple RUN instructions +RUN apt-get update +RUN apt-get install -y curl +RUN apt-get clean + +# Good: Single RUN instruction +RUN apt-get update && \ + apt-get install -y curl && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +``` + +**3. Use .dockerignore** +```dockerignore +node_modules +npm-debug.log +.git +.gitignore +README.md +.env +.nyc_output +coverage +.nyc_output +``` + +### Security Best Practices + +**1. Don't Run as Root** +```dockerfile +# Create non-root user +RUN addgroup -g 1001 -S appgroup && \ + adduser -S appuser -u 1001 -G appgroup + +# Switch to non-root user +USER appuser +``` + +**2. Use Specific Versions** +```dockerfile +# Bad: Latest tag +FROM node:latest + +# Good: Specific version +FROM node:18.17.0-alpine +``` + +**3. Minimize Attack Surface** +```dockerfile +# Remove package managers +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl && \ + apt-get purge -y --auto-remove apt-get && \ + rm -rf /var/lib/apt/lists/* +``` + +### Performance Optimization + +**1. Order Instructions by Change Frequency** +```dockerfile +# Dependencies change less frequently +COPY package*.json ./ +RUN npm ci --only=production + +# Source code changes more frequently +COPY . . +``` + +**2. Use Build Cache Effectively** +```dockerfile +# Cache npm dependencies +COPY package*.json ./ +RUN npm ci + +# Copy source code after dependencies +COPY . . +RUN npm run build +``` + +**3. Leverage Multi-Stage Builds** +```dockerfile +# Build stage with dev dependencies +FROM node:18-alpine AS builder +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +# Production stage with only runtime dependencies +FROM node:18-alpine AS production +COPY package*.json ./ +RUN npm ci --only=production +COPY --from=builder /app/dist ./dist +``` + +--- + +## Real-World Examples + +### Node.js Application + +```dockerfile +# Multi-stage build for Node.js app +FROM node:18-alpine AS base +WORKDIR /app +COPY package*.json ./ + +# Install dependencies +FROM base AS deps +RUN npm ci --only=production && npm cache clean --force + +# Build application +FROM base AS build +RUN npm ci +COPY . . +RUN npm run build + +# Production image +FROM node:18-alpine AS production +WORKDIR /app + +# Create non-root user +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nextjs -u 1001 + +# Copy dependencies and built application +COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules +COPY --from=build --chown=nextjs:nodejs /app/dist ./dist +COPY --chown=nextjs:nodejs package*.json ./ + +# Switch to non-root user +USER nextjs + +# Expose port and add health check +EXPOSE 3000 +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3000/health || exit 1 + +# Start application +CMD ["node", "dist/server.js"] +``` + +### Python Flask Application + +```dockerfile +# Use Python slim image +FROM python:3.11-slim AS base + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +# Install system dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + curl && \ + rm -rf /var/lib/apt/lists/* + +# Create non-root user +RUN useradd --create-home --shell /bin/bash app + +# Set working directory +WORKDIR /app + +# Install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY --chown=app:app . . + +# Switch to non-root user +USER app + +# Expose port +EXPOSE 5000 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:5000/health || exit 1 + +# Start application +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "app:app"] +``` + +### Go Application + +```dockerfile +# Build stage +FROM golang:1.21-alpine AS builder + +# Install git (required for go modules) +RUN apk add --no-cache git + +# Set working directory +WORKDIR /app + +# Copy go mod files +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy source code +COPY . . + +# Build binary +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . + +# Production stage +FROM scratch + +# Copy CA certificates for HTTPS +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ + +# Copy binary +COPY --from=builder /app/main /main + +# Expose port +EXPOSE 8080 + +# Run binary +ENTRYPOINT ["/main"] +``` + +--- + +## Advanced Dockerfile Features + +### Health Checks + +```dockerfile +# Basic health check +HEALTHCHECK --interval=30s --timeout=3s --retries=3 \ + CMD curl -f http://localhost:3000/health || exit 1 + +# Custom health check script +COPY healthcheck.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/healthcheck.sh +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD /usr/local/bin/healthcheck.sh + +# Disable inherited health check +HEALTHCHECK NONE +``` + +### Build Arguments and Environment Variables + +```dockerfile +# Build arguments +ARG NODE_VERSION=18 +ARG APP_VERSION=1.0.0 + +FROM node:${NODE_VERSION}-alpine + +# Environment variables +ENV NODE_ENV=production \ + APP_VERSION=${APP_VERSION} \ + PORT=3000 + +# Use in labels +LABEL version=${APP_VERSION} +``` + +### Conditional Instructions + +```dockerfile +# Using shell conditions +RUN if [ "$NODE_ENV" = "development" ]; then \ + npm install; \ + else \ + npm ci --only=production; \ + fi + +# Using build arguments +ARG INSTALL_DEV=false +RUN if [ "$INSTALL_DEV" = "true" ]; then \ + apt-get install -y development-tools; \ + fi +``` + +--- + +## Dockerfile Linting and Validation + +### Using Hadolint + +```bash +# Install hadolint +brew install hadolint + +# Lint Dockerfile +hadolint Dockerfile + +# Ignore specific rules +hadolint --ignore DL3008 --ignore DL3009 Dockerfile +``` + +### Common Dockerfile Issues + +1. **DL3008**: Pin versions in apt-get install +2. **DL3009**: Delete apt-get lists after installing +3. **DL3015**: Avoid additional packages by specifying --no-install-recommends +4. **DL4006**: Set SHELL option -o pipefail before RUN with a pipe + +--- + +## Testing Dockerfiles + +### Build and Test + +```bash +# Build image +docker build -t my-app:test . + +# Test image +docker run --rm my-app:test + +# Test with different build args +docker build --build-arg NODE_ENV=development -t my-app:dev . + +# Test specific stage +docker build --target test -t my-app:test . +``` + +### Image Analysis + +```bash +# Analyze image layers +docker history my-app:latest + +# Check image size +docker images my-app + +# Inspect image configuration +docker inspect my-app:latest + +# Scan for vulnerabilities +docker scout cves my-app:latest +``` + +--- + +## Troubleshooting Dockerfile Issues + +### Common Problems + +**Build Context Too Large** +```bash +# Use .dockerignore +echo "node_modules" >> .dockerignore +echo ".git" >> .dockerignore + +# Check build context size +docker build --no-cache . +``` + +**Layer Caching Issues** +```bash +# Disable cache +docker build --no-cache . + +# Clear build cache +docker builder prune +``` + +**Permission Issues** +```dockerfile +# Fix ownership +COPY --chown=user:group files /app/ + +# Set permissions +RUN chmod +x /app/script.sh +``` + +Ready to build efficient Docker images? Start with simple Dockerfiles and gradually implement advanced techniques! πŸš€ \ No newline at end of file diff --git a/docs/Docker/intro.md b/docs/Docker/intro.md index 1a45933e..799f5fc4 100644 --- a/docs/Docker/intro.md +++ b/docs/Docker/intro.md @@ -1,6 +1,21 @@ +--- +id: intro +title: Introduction to Docker +sidebar_label: Introduction to Docker +sidebar_position: 1 +tags: + [ + docker, + containers, + introduction, + containerization + ] +description: Learn Docker fundamentals - what containers are, why use Docker, core concepts like images and containers, and get started with essential Docker commands. +--- +
-# 🐳 Introduction to Docker +# Introduction to Docker
Welcome! Docker helps you package and run applications in containersβ€”think of them as lightweight, portable boxes that contain everything your app needs to run. @@ -77,60 +92,71 @@ docker logs my-app That's it! Your app is now running in a container. -## Essential Commands +## Next Steps -```bash -# Build an image -docker build -t myapp:1.0 . +1. **Install Docker** - Get Docker Desktop (Mac/Windows) or Docker Engine (Linux) +2. **Learn Docker Commands** - Master essential CLI commands +3. **Create Dockerfiles** - Build custom images +4. **Try Docker Compose** - Manage multi-container apps +5. **Explore Docker Hub** - Find pre-built images -# Run a container -docker run -d --name myapp -p 8080:80 myapp:1.0 +## Key Takeaways -# List running containers -docker ps +- **Containers** package your app with everything it needs +- **Images** are blueprints, containers are running instances +- **Dockerfiles** define how to build images +- **Docker Compose** manages multiple containers together +- Docker makes development, testing, and deployment much easier -# View logs -docker logs myapp +## What Can You Do with Docker? -# Stop a container -docker stop myapp +- **Web Development** - Containerize Node.js, Python, PHP applications +- **Microservices** - Build and deploy scalable service architectures +- **Development Environment** - Consistent dev setups across teams +- **CI/CD Pipelines** - Automated testing and deployment +- **Database Management** - Run isolated database instances +- **Cloud Deployment** - Deploy anywhere with container orchestration -# Remove a container -docker rm myapp +--- -# List images -docker images +### Docker vs Virtual Machines -# Remove an image -docker rmi myapp:1.0 -``` +| Feature | Docker Containers | Virtual Machines | +|---------|-------------------|------------------| +| **Resource Usage** | Lightweight, shares OS kernel | Heavy, full OS per VM | +| **Startup Time** | Seconds | Minutes | +| **Isolation** | Process-level | Hardware-level | +| **Portability** | High | Medium | +| **Performance** | Near-native | Overhead from hypervisor | +### Good to Know -## Best Practices +1. Docker containers share the host OS kernel, making them much more efficient than VMs +2. Container images are built in layers, enabling efficient storage and transfer +3. You can run multiple containers from the same image +4. Containers are **stateless** by default - use volumes for persistent data +5. Docker works on **Windows**, **macOS**, and **Linux** -βœ… **Use official base images** - `node:18-alpine`, `python:3.11-slim` -βœ… **Use specific tags** - Avoid `:latest` in production -βœ… **Keep images small** - Use Alpine or slim variants -βœ… **Add .dockerignore** - Exclude `node_modules`, `.git`, logs -βœ… **Don't run as root** - Create a non-privileged user -βœ… **Use volumes for data** - Never store important data in containers -βœ… **One process per container** - Keep it simple and focused +### Why is Docker so Popular? +Docker has revolutionized software development and deployment because: -## Next Steps +* **"It Works on My Machine" Problem Solved** + Docker ensures your application runs the same way everywhere, eliminating environment-related bugs. -1. **Install Docker** - Get Docker Desktop (Mac/Windows) or Docker Engine (Linux) -2. **Try the examples** - Build and run the sample Dockerfiles above -3. **Learn Docker Compose** - Manage multi-container apps easily -4. **Explore Docker Hub** - Find pre-built images for databases, web servers, etc. -5. **Read the docs** - https://docs.docker.com/ +* **Faster Development Cycles** + Developers can quickly spin up consistent environments without complex setup procedures. -## Key Takeaways +* **Efficient Resource Utilization** + Containers use fewer resources than virtual machines while providing similar isolation benefits. -- **Containers** package your app with everything it needs -- **Images** are blueprints, containers are running instances -- **Dockerfiles** define how to build images -- **Docker Compose** manages multiple containers together -- Docker makes development, testing, and deployment much easier +* **Simplified Deployment** + Package your application with all dependencies into a single, portable container image. + +* **Scalability** + Easily scale applications up or down by running multiple container instances. + +* **DevOps Integration** + Perfect fit for CI/CD pipelines, enabling automated testing and deployment workflows. -Ready to containerize your first app? Start with a simple Dockerfile and experiment! πŸš€ \ No newline at end of file +Ready to dive deeper? Let's explore Docker installation and setup in the next section! πŸš€ \ No newline at end of file diff --git a/docs/Docker/setup-environment.md b/docs/Docker/setup-environment.md new file mode 100644 index 00000000..48243857 --- /dev/null +++ b/docs/Docker/setup-environment.md @@ -0,0 +1,315 @@ +--- +id: setup-environment +title: Docker Installation & Setup +sidebar_label: Setup Environment +sidebar_position: 2 +tags: + [ + docker, + installation, + setup, + docker-desktop + ] +description: Learn how to install Docker on Windows, macOS, and Linux. Step-by-step guide to set up Docker Desktop and verify your installation. +--- + +# Docker Installation & Setup + +Setting up Docker is the first step to start containerizing your applications. This guide covers installation on all major operating systems. + +## System Requirements + +### Windows +- **Windows 10 64-bit**: Pro, Enterprise, or Education (Build 15063 or later) +- **Windows 11 64-bit**: Home or Pro version 21H2 or higher +- **WSL 2** feature enabled +- **Hyper-V** and **Containers** Windows features enabled + +### macOS +- **macOS 10.15** or newer +- **4 GB RAM** minimum +- **VirtualBox** prior to version 4.3.30 must be uninstalled + +### Linux +- **64-bit kernel** and CPU support for virtualization +- **KVM virtualization** support +- **QEMU** version 5.2 or newer +- **systemd** init system + +--- + +## Windows Installation + +### Method 1: Docker Desktop (Recommended) + +**Step 1: Download Docker Desktop** +1. Visit [Docker Desktop for Windows](https://www.docker.com/products/docker-desktop/) +2. Click "Download for Windows" +3. Run the installer `Docker Desktop Installer.exe` + +**Step 2: Installation Process** +1. Follow the installation wizard +2. Ensure "Use WSL 2 instead of Hyper-V" is checked +3. Complete the installation and restart your computer + +**Step 3: Enable WSL 2** +```powershell +# Run in PowerShell as Administrator +dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart +dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart + +# Restart your computer, then set WSL 2 as default +wsl --set-default-version 2 +``` + +**Step 4: Verify Installation** +```bash +docker --version +docker run hello-world +``` + +--- + +## macOS Installation + +### Docker Desktop for Mac + +**Step 1: Download** +1. Visit [Docker Desktop for Mac](https://www.docker.com/products/docker-desktop/) +2. Choose your chip type: + - **Apple Silicon (M1/M2)**: Mac with Apple chip + - **Intel**: Mac with Intel chip + +**Step 2: Install** +1. Open the downloaded `.dmg` file +2. Drag Docker to Applications folder +3. Launch Docker from Applications +4. Follow the setup assistant + +**Step 3: Verify Installation** +```bash +docker --version +docker run hello-world +``` + +### Alternative: Homebrew Installation +```bash +# Install Docker using Homebrew +brew install --cask docker + +# Start Docker Desktop +open /Applications/Docker.app +``` + +--- + +## Linux Installation + +### Ubuntu/Debian + +**Step 1: Update Package Index** +```bash +sudo apt update +sudo apt install apt-transport-https ca-certificates curl software-properties-common +``` + +**Step 2: Add Docker's GPG Key** +```bash +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +``` + +**Step 3: Add Docker Repository** +```bash +echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +``` + +**Step 4: Install Docker** +```bash +sudo apt update +sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin +``` + +**Step 5: Add User to Docker Group** +```bash +sudo usermod -aG docker $USER +newgrp docker +``` + +### CentOS/RHEL/Fedora + +**Step 1: Install Required Packages** +```bash +sudo yum install -y yum-utils +``` + +**Step 2: Add Docker Repository** +```bash +sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo +``` + +**Step 3: Install Docker** +```bash +sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin +``` + +**Step 4: Start Docker Service** +```bash +sudo systemctl start docker +sudo systemctl enable docker +sudo usermod -aG docker $USER +``` + +--- + +## Verification & Testing + +### Basic Verification +```bash +# Check Docker version +docker --version + +# Check Docker Compose version +docker compose version + +# View system information +docker system info + +# Test with hello-world +docker run hello-world +``` + +### Advanced Testing +```bash +# Run a simple web server +docker run -d -p 8080:80 --name test-nginx nginx + +# Check if it's running +docker ps + +# Test in browser: http://localhost:8080 + +# Clean up +docker stop test-nginx +docker rm test-nginx +``` + +--- + +## Docker Desktop Features + +### Dashboard +- **Visual container management** +- **Image browsing and management** +- **Volume and network management** +- **Extension marketplace** + +### Settings Configuration +1. **Resources**: Adjust CPU, Memory, Swap, Disk usage +2. **File Sharing**: Configure shared directories +3. **Proxies**: Set up corporate proxy settings +4. **Docker Engine**: Advanced daemon configuration + +### Useful Commands +```bash +# Start Docker Desktop +# Windows: Start from Start Menu +# macOS: Open from Applications +# Linux: systemctl start docker + +# Check Docker Desktop status +docker system info + +# Update Docker Desktop +# Use built-in updater or download latest version +``` + +--- + +## Troubleshooting Common Issues + +### Windows Issues + +**WSL 2 Installation Failed** +```powershell +# Enable Windows features manually +Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux +Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform + +# Download and install WSL 2 kernel update +# https://aka.ms/wsl2kernel +``` + +**Docker Desktop Won't Start** +- Ensure Hyper-V is enabled +- Check Windows version compatibility +- Restart Docker Desktop service + +### macOS Issues + +**Permission Denied** +```bash +# Fix Docker socket permissions +sudo chown $USER /var/run/docker.sock +``` + +**Resource Allocation** +- Increase memory allocation in Docker Desktop settings +- Close other resource-intensive applications + +### Linux Issues + +**Permission Denied** +```bash +# Add user to docker group +sudo usermod -aG docker $USER +# Log out and log back in +``` + +**Docker Daemon Not Running** +```bash +# Start Docker service +sudo systemctl start docker +sudo systemctl enable docker + +# Check status +sudo systemctl status docker +``` + +--- + +## Next Steps + +Now that Docker is installed and running: + +1. βœ… **Learn Docker Commands** - Master essential Docker CLI commands +2. βœ… **Create Your First Dockerfile** - Build custom images +3. βœ… **Explore Docker Hub** - Find and use existing images +4. βœ… **Try Docker Compose** - Manage multi-container applications + +**Congratulations!** πŸŽ‰ You now have Docker running on your system. Ready to start containerizing applications! + +--- + +## Quick Reference + +### Installation Commands Summary + +**Ubuntu/Debian:** +```bash +curl -fsSL https://get.docker.com -o get-docker.sh +sudo sh get-docker.sh +sudo usermod -aG docker $USER +``` + +**CentOS/RHEL:** +```bash +curl -fsSL https://get.docker.com -o get-docker.sh +sudo sh get-docker.sh +sudo systemctl start docker +sudo usermod -aG docker $USER +``` + +**Verification:** +```bash +docker --version && docker run hello-world +``` \ No newline at end of file diff --git a/sidebars.ts b/sidebars.ts index 11ec70b3..77b56e5b 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -204,6 +204,29 @@ const sidebars: SidebarsConfig = { "Nextjs/project-structure", ], }, + { + type: "category", + label: "Docker", + className: "custom-sidebar-docker", + customProps: { + icon: "/icons/docker.svg" + }, + items: [ + "Docker/intro", + "Docker/setup-environment", + "Docker/docker-commands", + "Docker/dockerfile-guide", + { + type: "category", + label: "Docker Compose", + className: "custom-sidebar-docker-compose", + items: [ + "Docker/docker-compose", + "Docker/docker-compose-advanced", + ], + }, + ], + }, { type: "category", label: "πŸŽ“ Google Student Ambassador", diff --git a/src/theme/DocSidebarItem/Category/index.tsx b/src/theme/DocSidebarItem/Category/index.tsx index e1b4f191..0b513ff9 100644 --- a/src/theme/DocSidebarItem/Category/index.tsx +++ b/src/theme/DocSidebarItem/Category/index.tsx @@ -27,6 +27,7 @@ import { Code2, School, Zap, + Container, ChevronDown, ChevronUp, ChevronRight, @@ -74,6 +75,8 @@ const getIcon = ( className?.includes("gsa") ) { return ; + } else if (label.includes("Docker") || className?.includes("docker")) { + return ; } else if (label.includes("Technical") || className?.includes("technical")) { return (