Docker Fundamentals with Mumshad Mannambeth
Docker Fundamentals with Mumshad Mannambeth
wiki/3N3A4kt
Advanced
Advanced
DOCKER ADVANCED
• Lecture
• Demos
• Coding Exercises
• Assignment
PRE-REQUISITES
❑
✓Docker Overview ❑Docker Architecture
❑
✓Running Docker Containers ❑Docker For Windows
❑
✓Creating a Docker Image ❑Docker Service
❑
✓Docker Compose ❑Docker Swarm
❑
✓Docker Swarm ❑Overlay Networks
❑
✓Networking in Docker ❑Load Balancing
❑CI/CD Integration
DOCKER STORY
• 64-bit operating
• Windows 7 or higher.
• Virtualization is enabled
• Oracle Virtualbox
• Docker Engine
• Docker Machine
• Docker Compose
• Kitematic GUI
2. DOCKER FOR WINDOWS
Kernel Kernel
Base Images:
• Nano Server
Support
• Windows Server 2016
• Nano Server
• Windows 10 Professional and Enterprise (Hyper-V Isolated Containers)
DOCKER ENGINE
Docker CLI
REST API
InterProcess
NAMESPACE - PID
Linux System
PID : 1
PID : 2
PID : 3
Child System (Container)
PID : 4
PID : 5 PID : 1
PID : 6 PID : 2
CGROUPS
Linux System
CPU Memory
/var/lib/docker
aufs
containers
image
volumes
LAYERED ARCHITECTURE
Dockerfile Dockerfile2
FROM Ubuntu FROM Ubuntu
RUN apt-get update && apt-get –y install python RUN apt-get update && apt-get –y install python
RUN pip install flask flask-mysql RUN pip install flask flask-mysql
Read Write
Container Layer
Layer 6. Container Layer
Read Only
Layer 5. Update Entrypoint with “flask” command
Layer 4. Source code
Read Write
Container Layer
[Link]
Read Only
/var/lib/mysql /var/lib/mysql
data_volume mysql
/var/lib/docker/volumes /data
Read Only
mysql – image layer
Docker Host
STORAGE DRIVERS
• AUFS
• ZFS
• BTRFS
• Device Mapper
• Overlay
• Overlay2
DOCKER COMPOSE
[Link]
services:
web:
image: “mmumshad/simple-webapp"
database:
image: “mongodb“
messaging:
image: "redis:alpine“
orchestration:
image: “ansible“
docker-compose up
SAMPLE APPLICATION – VOTING APPLICATION
voting-app result-app
python NodeJS
C
in-memory DB db
PostgreSQL
CATS DOGS
0
1 0
worker
.NET
DOCKER RUN --LINKS
docker run -d --name=redis redis voting-app result-app
docker run -d --name=db postgres:9.4
worker
! Deprecation Warning
DOCKER COMPOSE
image:
docker run -d --name=redis
redis: redis
redis [Link]
image:
docker run -d --name=db
db: postgres:9.4
postgres:9.4
ports: links:
docker run -d --name=vote
vote:–p- 5000:80 --link
- redis:redis
redis voting-app
image: voting-app
ports: links:
docker run -d --name=result
result:–p - db db:db result-app
- 5001:80 --link
image: result-app
docker run -d --name=worker links:
worker:--link db:db --link redis:redisimage:
workerworker
- redis
- db
db:db = db
docker-compose up
DOCKER COMPOSE - BUILD
[Link] [Link]
redis: redis:
image: redis image: redis
db: db:
image: postgres:9.4 image: postgres:9.4
vote: vote:
image: voting-app build: ./vote
ports: ports:
- 5000:80 - 5000:80
links: links:
- redis - redis
result: result:
image: result build: ./result
ports: ports:
- 5001:80 - 5001:80
links: links:
- db - db
worker: worker:
image: worker build: ./worker
links: links:
- db - db
- redis - redis
DOCKER COMPOSE - VERSIONS
[Link] [Link] [Link]
redis: version: 2 version: 3
services: services:
image: redis
redis:
db:
image: redis
image: postgres:9.4
db:
vote:
image: postgres:9.4
image: voting-app
vote:
ports:
image: voting-app
- 5000:80
ports:
links:
- 5000:80
- redis
depends_on:
- redis
Docker Swarm
MySQL
Container
docker swarm init docker swarm join docker swarm join docker swarm join
Leader
Docker Host Docker Host Docker Host
L
L
DISTRIBUTED CONSENSUS - RAFT
DB
D
Instruction
DB DB
HOW MANY MANAGER NODES?
• Docker Recommends – 7 Managers
• No limit on Managers
4 3 1
5 3 2
6 4 2
N-1
7 4 3 Fault Tolerance of N =
2
ODD OR EVEN?
1 1 0
2 2 0
3 2 1
4 3 1
5 3 2
6 4 2
7 4 3
CLUSTER FAILURE
Web Server Web Server Web Server Web Server Web Server
Docker Host Docker Host Docker Host Docker Host Docker Host
docker node promote
Web Server
Docker Host
Docker Swarm
TASKS
docker service create –replicas=3 my-web-server
Orchestrator
Scheduler
Manager Node
Web Server
Docker Swarm
REPLICAS
docker service create –replicas=3 my-web-server
Docker Swarm
REPLICAS VS GLOBAL
docker service create --replicas=3 my-web-server
Docker Swarm
SERVICE NAME
docker service create --replicas=3 --name web-server
my-web-server
Docker Swarm
SERVICE UPDATE
docker service create –replicas=3 --name web-server my-web-server
Docker Swarm
DOCKER NETWORKING
docker run ubuntu docker run Ubuntu –-network=none docker run Ubuntu --network=host
5000 5000
Web Web
Container Container
Overlay Network
[Link]
[Link]
[Link]
–p 80:5000 \
my-web-server
5000 5000
Web Web
Container Container
[Link] [Link]
docker0
[Link]
Docker Host
Docker Swarm
INGRESS NETWORK
80 80 80
Routing Mesh
5000 5000
Web Web
Container Container
Host IP
[Link]( [Link]
mysql ) web mysql web [Link]
Container Container
[Link] [Link] mysql [Link]
docker0
DNS
Server
[Link]
Docker Host
OVERLAY NETWORK
docker network create --driver overlay --subnet [Link]/24 my-overlay-network
Overlay Network
[Link]
[Link] [Link]
version: 3
services: services:
web: web:
image: “mmumshad/simple-webapp" image: “mmumshad/simple-webapp"
database: database:
image: “mongodb“ image: “mongodb“
messaging: messaging:
image: "redis:alpine“ image: "redis:alpine“
orchestration: orchestration:
image: “ansible“ image: “ansible“
Stack
Container
Service Service
Container
Container Container
Service
Stack
SAMPLE APPLICATION IN SWARM
• Multiple Instances
• Placement Preferences
• Resource Constraints
Docker Swarm
STACK DEFINITION - REPLICA
[Link]
version: 3
services:
redis:
image: redis
deploy:
replicas: 1
db:
image: postgres:9.4
deploy:
replicas: 1
vote:
image: voting-app
deploy:
replicas: 2
result:
image: result
deploy:
replicas: 1
worker:
image: worker
deploy:
replicas: 1
STACK DEFINITION - PLACEMENT
[Link]
version: 3
services:
redis:
image: redis
deploy:
replicas: 1
db:
image: postgres:9.4
deploy:
placement:
constraints:
- [Link] == node1
- [Link] == manager
STACK DEFINITION - RESOURCES
[Link]
version: 3
services:
redis:
image: redis
deploy:
replicas: 1
resources:
limits:
cpus: 0.01
memory: 50M
CI/CD
Test
Feature #1 Build System Framework
Code Repository
✓ Unit Test
✓ Web UI Test
✓ Integration Test
Feature #2
Robot
Framework
BugFix #1
Continuous Integration
CD – CONTINUOUS DELIVERY/DEPLOYMENT
Production Environment
Release
Management
CI
Continuous Delivery
Continuous Deployment
CI/CD - DOCKER
Test
Framework
Build System
Code Release
Repository
my-app:1.0
Docker
Hub
Dockerfile
Robot
Framework
Docker Plugin
Continuous Integration
Continuous Delivery
PUBLIC CLOUD – DOCKER SUPPORT
• GitHub
• BitBucket
Build Images
Manage Configure
Nodes Docker
Configure
Swarm
DOCKER CLOUD - BUILD
Docker
Hub
Docker Cloud
KUBERNETES
• Introduction
• Architecture Basics
• Services
• Deployment
• GCP Kubernetes
CONTAINER ORCHESTRATION
Docker Swarm
MySQL
Container
IP Address
Kube Worker Kube Worker
Container1 Container2
Storage
Pod
Kube Worker
KUBERNETES - DEPLOYMENT
Web Server
Pod
POD POD
redis db redis db
Service
Service
worker POD
worker • Internal – ClusterIP
• External - LoadBalancer
KUBECTL
Version v1 [Link]
apiVersion: v1
spec:
Specification containers ports
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
POD POD
redis db
Service
Service
POD
worker
DEMO
❑
✓Docker Architecture
❑
✓Docker For Windows
❑
✓Docker Service
❑
✓Docker Swarm
❑
✓Overlay Networks
❑
✓Load Balancing
❑
✓CI/CD Integration
Learn more about DevOps and Cloud courses with KodeKloud: [Link]