Open-source platform for containerization: packages apps + dependencies into lightweight, portable containers; enables consistent “build once, run anywhere”; core = Docker Engine; includes Docker Desktop (local dev), Docker Compose (multi-container), Docker Hub (image registry).
Who created Docker?
Created by Solomon Hykes at dotCloud (now Docker, Inc.) in 2013; open-source core (Moby project) maintained by community + Docker, Inc.; widely used by developers, DevOps, SREs, enterprises (e.g., Google, AWS, Microsoft, Netflix).
Why use Docker?
Solves “it works on my machine” by ensuring identical environments; lightweight vs VMs (shares host kernel); fast startup, high density, portability, reproducibility; accelerates dev/test/deploy cycles; standard for microservices, CI/CD, cloud-native apps.
Where to use Docker?
Runs on Linux natively (Engine); via Docker Desktop on macOS/Windows (uses VM/hypervisor); manages containers on servers, clouds (AWS ECS, Azure ACI, GCP), Kubernetes (via containerd/CRI), laptops, CI/CD pipelines; global adoption across dev, cloud, enterprise.
How to use Docker?
Client-server architecture: Docker CLI talks to Docker daemon → pulls/builds images (layered filesystem) → runs containers (isolated processes with namespaces/cgroups); key commands: docker run, docker build, docker compose up; images from registries like Docker Hub.
# List networks
docker network ls
docker network inspect <network>
# Create networks
docker network create <name>
docker network create --driver bridge <name>
docker network create --subnet=172.20.0.0/16 <name>
# Connect containers to network
docker network connect <network> <container>
docker network disconnect <network> <container>
# Remove networks
docker network rm <network>
docker network prune # Remove unused networks# Run container with network
docker run --network <network> <image>
docker run --network host <image> # Use host network
docker run -p 8080:80 <image> # Port mapping
docker run -p 127.0.0.1:8080:80 <image> # Bind to specific interface
Port Mapping
1
2
3
4
5
# Publish ports
docker run -p 8080:80 <image> # Map host:container
docker run -p 80:80/tcp <image> # Specify protocol
docker run -P <image> # Publish all exposed ports
docker run -p 8080-8090:80-90 <image> # Port range
Volumes & Data Management
Volume Operations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# List volumes
docker volume ls
docker volume inspect <volume>
# Create volumes
docker volume create <name>
docker volume create --driverlocal <name>
# Remove volumes
docker volume rm <volume>
docker volume prune # Remove unused volumes# Mount volumes
docker run -v /host/path:/container/path <image>
docker run -v volume_name:/container/path <image>
docker run --mounttype=bind,source=/host,target=/container <image>
docker run --mounttype=volume,source=vol,target=/container <image>
Bind Mounts vs Volumes
1
2
3
4
5
6
7
8
9
10
11
# Bind mount (host path)
docker run -v /host/data:/app/data <image>
# Named volume
docker run -v mydata:/app/data <image>
# Anonymous volume
docker run -v /app/data <image>
# tmpfs mount (in-memory)
docker run --tmpfs /tmp <image>
# Use specific tags, not 'latest'FROM python:3.11-slim# Use multi-stage builds for smaller imagesFROMnode:18ASbuilder# ... build stepsFROM node:18-alpineCOPY --from=builder /app/dist /app# Order commands by change frequency# Install dependencies first (cached)COPY requirements.txt .RUN pip install-r requirements.txt
# Copy application code lastCOPY . .# Use .dockerignore# node_modules/# .git/# *.log# Run as non-root userRUN useradd -m appuser
USER appuser# Use exec form for CMD/ENTRYPOINTCMD ["python", "app.py"] # GoodCMD python app.py # Bad (shell form)
Security Best Practices
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Scan images for vulnerabilities
docker scan <image>
# Run as non-root
docker run --user 1000:1000 <image>
# Limit capabilities
docker run --cap-drop ALL --cap-add NET_BIND_SERVICE <image>
# Read-only filesystem
docker run --read-only <image>
# Security options
docker run --security-opt no-new-privileges <image>
docker run --security-optapparmor=profile <image>