0% found this document useful (0 votes)
2 views2 pages

Docker Guide

This guide provides a comprehensive overview of Docker Desktop, covering architecture, setup, basic commands, data persistence, networking, multi-container composition, and production optimization. It includes practical examples and commands for building images, managing containers, and optimizing applications with Docker Compose. Additionally, it offers advanced operations and debugging techniques to enhance user proficiency with Docker.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Docker Guide

This guide provides a comprehensive overview of Docker Desktop, covering architecture, setup, basic commands, data persistence, networking, multi-container composition, and production optimization. It includes practical examples and commands for building images, managing containers, and optimizing applications with Docker Compose. Additionally, it offers advanced operations and debugging techniques to enhance user proficiency with Docker.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Docker Desktop: Complete Practice Guide MASTERY GUIDE

From Beginner to Advanced • Architecture, Hands-on CLI, Compose & Optimization

1. DOCKER ARCHITECTURE & SETUP

🏗️ High-Level Architecture ⚙️ Core Definitions & Settings


• Image: Read-only template with code, libs & config.
+-------------------------------------------------------+
• Container: Isolated, runnable instance of an image.
| Docker Host |
| +--------------------+ +--------------------+ | • Registry: Storage service for Docker images (Docker Hub).
| | Container A | | Container B | | • Desktop Settings: Allocate CPU/RAM under Resources; toggle local K8s
| | [ App / Code ] | | [ App / Code ] | | under Kubernetes.
| | [ Dependencies ] | | [ Dependencies ] | |
| +--------^-----------+ +--------^-----------+ |
| | | |
| +--------+----------------------------+-----------+ |
| | Image | |
| +-------------------------^-----------------------+ |
+----------------------------|--------------------------+
pull / push | [ Docker Registry ]

2. BASIC COMMANDS & BUILDING IMAGES

🚀 First Container & Lifecycle Commands 📦 Custom Dockerfile & Build

# Run Nginx on port 8080 # Dockerfile


docker run -d -p 8080:80 --name my-web nginx FROM node:20-alpine
WORKDIR /app
# Check running containers COPY package*.json ./
docker ps RUN npm install
COPY . .
# Stream logs & exec terminal EXPOSE 3000
docker logs -f my-web CMD ["npm", "start"]
docker exec -it my-web bash
# Build & Run Commands
# Stop and remove docker build -t my-node-app:v1 .
docker stop my-web && docker rm my-web docker run -d -p 3000:3000 --name node-app my-node-
app:v1

3. DATA PERSISTENCE & NETWORKING

💾 Storage Volumes Comparison 🌐 Custom Isolation Networking

Type Location Primary Use Case # Create custom bridge network


Named Volume Managed by Docker Persistent DB Storage docker network create app-net

Bind Mount Host File System Live Dev / Hot Reload # Connect containers on same network
docker run -d --name db --network app-net -e
tmpfs Mount Host System RAM Non-persistent Secrets
POSTGRES_PASSWORD=secret postgres:16-alpine

# Named Volume:
docker run -d --name web --network app-net -p 8080:80
docker run -d -v db_data:/var/lib/postgresql/data
nginx
postgres:16-alpine
# Inspect network topology
# Bind Mount (Development):
docker network inspect app-net
docker run -d -v $(pwd):/app -p 3000:3000 my-node-app:v1

4. MULTI-CONTAINER COMPOSE & PRODUCTION OPTIMIZATION


🐙 [Link] Structure ⚡ Multi-Stage Builds & Security

version: '3.8' # Multi-Stage Dockerfile (Ultra Small Image)


services: # Stage 1: Build
web-frontend: FROM node:20-alpine AS builder
build: ./frontend WORKDIR /app
ports: ["80:80"] COPY package*.json ./
depends_on: [api-backend] RUN npm ci
networks: [frontend-net] COPY . .
RUN npm run build
api-backend:
build: ./backend # Stage 2: Minimal Runtime
ports: ["5000:5000"] FROM nginx:alpine
environment: COPY --from=builder /app/dist /usr/share/nginx/html
- DB_HOST=postgres-db EXPOSE 80
depends_on: CMD ["nginx", "-g", "daemon off;"]
postgres-db:
condition: service_healthy # Security & Scanning Commands
networks: [frontend-net, backend-net] USER node # Non-root user
docker scout quickview # Quick vulnerability scan
postgres-db: docker scout cves image:v1 # Scan CVE details
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: secret
volumes: [pgdata:/var/lib/postgresql/data]
networks: [backend-net]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]

networks:
frontend-net:
backend-net:
volumes:
pgdata:

5. ADVANCED OPERATIONS & DEBUGGING CHEAT SHEET

docker compose up -d / down -v Start multi-container app in background / Tear down with volumes
docker system df & docker system prune -a --volumes View disk space used by Docker & perform deep cleanup of unused resources
docker inspect <id> | docker stats View detailed JSON configurations | Stream real-time CPU, RAM & I/O metrics
docker tag my-app:v1 user/my-app:v1 && docker push user/my-app:v1 Tag local image for registry and push to Docker Hub

Docker Desktop Complete Guide • Page 1 of 1 Reference

You might also like