02 - Docker
02 - Docker
2
© takima 2022 all rights reserved²
Once upon a time...
Use case
Simple 3-Tiers application
3
© takima 2022 all rights reserved²
Once upon a time...
Multiple services / single server
Your application is getting complex… Company
‒ with multiple backend
■ with multiple languages
‒ with a lot of config
■ http servers, SSL certs, firewalls, LDAP, …
‒ … and harder to (re)deploy
‒ no process isolation
■ bad for security & resiliency*
PROS? CONS?
5
© takima 2022 all rights reserved²
Once upon a time...
Multiple services / multiple servers
Your application is getting complex… Company
‒ Put things in bare-metal servers!
‒ Great performance
‒ Perfect process isolation
‒ Costly
‒ Harder to deploy and manage
‒ No automatic scaling
6
© takima 2022 all rights reserved²
Once upon a time...
Multiple services / multiple VMs
Your application is getting complex… Company
‒ Put things in bare-metal servers!
VM 1 VM 2
‒ Put things in VMs*.
PROS?
VM 3
8
© takima 2022 all rights reserved²
Containers
Why ?
9
© takima 2022 all rights reserved²
Containers
Why ?
Your application is getting complex… Company
CONS?
VM 3
10
© takima 2022 all rights reserved²
Containers
Why ?
Your application is getting complex… Company
12
© takima 2022 all rights reserved²
Docker
containers, containers everywhere !
13
© takima 2022 all rights reserved²
Docker
Containers
‒ Open source
‒ Docker != VM. Docker ≈ lightweight VM
■ Package application and its dependencies
■ Isolate processes
‒ One usage = One container
■ eg: front-end + back-end + 1 DB = 3 containers
‒ Build once, ship everywhere
■ One docker image for all environment
‒ Version Control
■ Versioned images
14
© takima 2022 all rights reserved²
Docker
Containers vs VM
VM1 VM2
Guest OS Guest OS
Host Hardware
(RAM, CPU, NIC, …)
15
© takima 2022 all rights reserved²
Docker
Containers vs VM
Docker1 Docker2
Host Hardware
(RAM, CPU, NIC, …)
16
© takima 2022 all rights reserved²
Take away
17
© takima 2022 all rights reserved²
Docker stuff
Images, containers, volumes, networks...
18
© takima 2022 all rights reserved²
Docker
Images
Containers are made out of images
‒ image ≈ immutable, static
container
‒ one image = one usage
■ java + db + python = 3 images
■ reusable
■ minimal size
‒ built with Dockerfile
19
© takima 2022 all rights reserved²
Docker
Dockerfile
‒ “makefile” recipe to create an # Base image
20
© takima 2022 all rights reserved²
Docker
Dockerfile
from Dockerfile to image
latest
+ java:
+ conf
+ jar
+ ...
latest
+ java: >$ docker build >$ docker run
+ conf
+ jar
+ ...
22
© takima 2022 all rights reserved²
Docker
Containers
‒ live, running copies of images
23
© takima 2022 all rights reserved²
Containers commands
# Run a nginx container with name my-nginx
docker container run \
--name my-nginx \ # with container name=my-nginx
-it \ # with interactive terminal
-d \ # daemon mode (not linked to a terminal)
nginx:1.15.8 # based on specific nginx 1.15.8 image
24
© takima 2022 all rights reserved²
Docker # create a network
Networks docker network create -d bridge public-net
25
© takima 2022 all rights reserved²
Docker
Volumes
# bind-mount a volume
‒ “Containers are stateless:” docker run -d \
■ Keep no valuable data
--name my-nginx \
■ Can be destroyed or replaced,
-v "$(pwd)"/hostDir:/containerDir \
anytime
nginx
‒ Volumes
■ are a safe place on host
■ shared between containers
■ survive to container’s destruction
26
© takima 2022 all rights reserved²
Docker
Volumes use if you want to share files between host and container
# bind-mount a volume
‒ Bind-Mount volumes docker run -d \
■ mount a host folder into the
--name my-nginx \
container
-v "$(pwd)"/hostDir:/containerDir \
■ are OS dependent
nginx
■ let the container add files that
are owned by root
use if you want files on a safe place, without the need of
accessing them
# bind-mount a volume
‒ Named volumes docker volume create my-volume
■ are managed by docker engine
■ can be on a remote machine docker run -d \
■ cannot be accessed directly by --name my-nginx \
host -v my-volume:/containerDir \
nginx
27
© takima 2022 all rights reserved²
Take away
# bind-mount a volume
docker run -d \
--name my-nginx \
-v "$(pwd)"/hostDir:/containerDir:ro \
nginx
28
© takima 2022 all rights reserved²
Docker universe
Docker-compose, Docker HUB & co
29
© takima 2022 all rights reserved²
Docker universe
Docker compose
‒ Manage multiple containers # docker-compose.yml
together
■ build, run, build & run, start, stop version: "3"
‒ Declarative YAML Syntax services:
■ Services (= containers) myapp-web:
■ Networks image: "nginx:latest"
■ Volumes ports:
- "8080:80"
myapp-mysql:
image: "mysql:latest"
30
© takima 2022 all rights reserved²
Docker universe
Docker HUB
‒ “github” for docker
■ public place to store docker images
‒ host docker images
■ images are already built
‒ official & unofficial images
31
© takima 2022 all rights reserved²
Docker universe
Go Deeper
‒ Docker is a great tool but most of
the time production requires
■ Multi instances deployment
■ Vertical and / or Horizontal scaling
■ Fault tolerance on instance crashes
‒ Say Hello to : Containers
Orchestration
■ Deploy, manage and expose
containers on multiple instances
32
© takima 2022 all rights reserved²
Contributors
Thank you.
‒ Nicolas THIERION <[email protected]>
‒ Quentin BISSON <[email protected]>
‒ Aurélien MORREAU <[email protected]>
Lab: https://guide.master3.takima.io/docker-01
See also
Leave feedback: feedback form
‒ 01 - Devops
‒ 03 - Gitlab CI
‒ 04- Ansible (Bonus)
Contact [email protected]
© takima 2022 all rights reserved²
Références
● Why docker
● https://docs.docker.com/
34
© takima 2022 all rights reserved²