Docker For Beginners Mumshad Mannambeth

Download as pdf or txt
Download as pdf or txt
You are on page 1of 138
At a glance
Powered by AI
The key takeaways are that containers provide a lightweight virtualization method compared to virtual machines, and Docker is a tool that allows for easy deployment and management of containers. Docker Swarm and Kubernetes are both container orchestration platforms, with Docker Swarm providing basic clustering of Docker hosts and Kubernetes providing additional features like self-healing, horizontal pod autoscaling, and service discovery.

Containers virtualize the operating system instead of hardware. This makes them more portable and lightweight than virtual machines. Containers share the host operating system kernel and isolate resources like CPU, memory, storage and network access. In contrast, virtual machines run a full copy of an operating system and require a hypervisor.

Docker Swarm provides basic clustering of Docker hosts into a single virtual Docker engine with features like service discovery, load balancing and rolling updates. It allows deploying and scaling applications across multiple Docker hosts. However, it does not provide additional capabilities like self-healing and horizontal pod autoscaling that Kubernetes does.

docker

for beginners
MUMSHAD
MANNAMBETH w w w . k o d e k l o u d . c o m
Objectives
➢ What are Containers?
➢ What is Docker?
➢ Why do you need it?
➢ What can it do?

➢ Run Docker Containers


➢ Create a Docker Image
➢ Networks in Docker
➢ Docker Compose

➢ Docker Concepts in Depth

➢ Docker for Windows/Mac

➢ Docker Swarm
➢ Docker vs Kubernetes
docker
overview
Why do you need docker?
Web Server Database Messaging Orchestration

• Compatibility/Dependency
• Long setup time
• Different Dev/Test/Prod
environments
The Matrix from Hell !!

Libraries Dependencies

OS

Hardware Infrastructure
What can it do?
Container Container Container Container

• Containerize Web Server Database Messaging Orchestration

Applications
• Run each service with its
own dependencies in
separate containers

Libs Deps Libs Deps Libs Deps Libs Deps

Docker
?

OS

Hardware Infrastructure
What are containers?

Processes Processes Processes Processes


Network Network Network Network
Mounts Mounts Mounts Mounts

Docker

OS Kernel
Operating System

OS

Software Software Software Software

OS Kernel
Sharing the kernel

Software Software Software Software

Docker

OS - Ubuntu
Containers vs Virtual Machines


GB ✓
✓ MB
✓ ✓
Utilization Size Boot up Utilization Size Boot up

Virtual Machine Virtual Machine


Container Container
Application Application
Application Application
Libs Deps Libs Deps
OS OS Libs Deps Libs Deps

Docker
Hypervisor
OS

Hardware Infrastructure Hardware Infrastructure


Containers & Virtual Machines
Virtual Machine Virtual Machine
Container Container Container Container

Application Application Application Application


Libs Deps Libs Deps Libs Deps Libs Deps

Docker Docker
OS OS

Hypervisor
OS

Hardware Infrastructure
Hardware Infrastructure
How is it done? Public Docker registry - dockerhub

docker run ansible

docker run mongodb

docker run redis

docker run nodejs

docker run nodejs

docker run nodejs


Container vs image

Docker Container #1

Docker Image

Package Docker Container #2


Template
Plan

Docker Container #3
d o c k e r

Getting Started
Docker Editions

Community Edition Enterprise Edition


Community Edition

Linux MAC Windows Cloud


docker
commands
Run – start a container
docker run nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
fc7181108d40: Already exists
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest
ps – list containers
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 80/tcp silly_sammet

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds silly_sammet
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata
STOP – stop a container
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 80/tcp silly_sammet

docker stop silly_sammet


silly_sammet

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
796856ac413d nginx "nginx -g 'daemon of…" 7 seconds ago Exited (0) 3 seconds ago silly_sammet
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata
Rm – Remove a container
docker rm silly_sammet
silly_sammet

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
cff8ac918a2f redis "docker-entrypoint.s…" 6 seconds ago Exited (0) 3 seconds ago relaxed_aryabhata
images – List images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f68d6e55e065 4 days ago 109MB
redis latest 4760dc956b2d 15 months ago 107MB
ubuntu latest f975c5035748 16 months ago 112MB
alpine latest 3fd9065eaf02 18 months ago 4.14MB
rmi – Remove images
docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Deleted: sha256:f68d6e55e06520f152403e6d96d0de5c9790a89b4cfc99f4626f68146fa1dbdc
Deleted: sha256:1b0c768769e2bb66e74a205317ba531473781a78b77feef8ea6fd7be7f4044e1
Deleted: sha256:34138fb60020a180e512485fb96fd42e286fb0d86cf1fa2506b11ff6b945b03f
Deleted: sha256:cf5b3c6798f77b1f78bf4e297b27cfa5b6caa982f04caeb5de7d13c255fd7a1e

! Delete all dependent containers to remove image


Pull – download an image
docker run nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
fc7181108d40: Already exists
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest

docker pull nginx


Using default tag: latest
latest: Pulling from library/nginx
fc7181108d40: Pull complete
d2e987ca2267: Pull complete
0b760b431b11: Pull complete
Digest:
sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Status: Downloaded newer image for nginx:latest
docker run ubuntu

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS


45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago
docker run ubuntu

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS


45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago
Append a command
docker run ubuntu

docker run ubuntu sleep 5

5
4
3
2
1
Exec – execute a command
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
538d037f94a7 ubuntu "sleep 100“ 6 seconds ago Up 4 seconds distracted_mcclintock

docker exec distracted_mcclintock cat /etc/hosts


127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.2 538d037f94a7
Run – attach and detach
docker run kodekloud/simple-webapp
This is a sample web application that displays a colored background.
* Serving Flask app "app" (lazy loading)
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

docker run –d kodekloud/simple-webapp


a043d40f85fefa414254e4775f9336ea59e19e5cf597af5c554e0a35a1631118

docker attach a043d


docker

run
Run – tag
docker run redis
Using default tag: latest
latest: Pulling from library/redis
f5d23c7fed46: Pull complete
Status: Downloaded newer image for redis:latest

1:C 31 Jul 2019 09:02:32.624 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo


1:C 31 Jul 2019 09:02:32.624 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:M 31 Jul 2019 09:02:32.626 # Server initialized

docker run redis:4.0 TAG


Unable to find image 'redis:4.0' locally
4.0: Pulling from library/redis
e44f086c03a2: Pull complete
Status: Downloaded newer image for redis:4.0

1:C 31 Jul 09:02:56.527 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo


1:C 31 Jul 09:02:56.527 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=1, just started
1:M 31 Jul 09:02:56.530 # Server initialized
RUN - STDIN
~/prompt-application$ ./app.sh
Welcome! Please enter your name: Mumshad

Hello and Welcome Mumshad!

docker run kodekloud/simple-prompt-docker

Hello and Welcome !

docker run –i kodekloud/simple-prompt-docker


Mumshad

Hello and Welcome Mumshad!

docker run –it kodekloud/simple-prompt-docker


Welcome! Please enter your name: Mumshad

Hello and Welcome Mumshad!


Run – PORT mapping
docker run kodekloud/webapp
http://192.168.1.5:80
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
80 8000 8001

IP: 192.168.1.5

http://172.17.0.2:5000 Internal IP
5000 5000 5000

IP: 172.17.0.2 IP: 172.17.0.3 IP: 172.17.0.4


docker run –p 80:5000 kodekloud/simple-webapp 3
3 Web APP Web APP Web APP
0 Docker Container Docker Container Docker Container
docker run –p 8000:5000 kodekloud/simple-webapp 6
3 IP: 172.17.0.5 3 IP: 172.17.0.6 3 IP: 172.17.0.6
3 MySQL 3 MySQL 3 MySQL
docker run –p 8001:5000 kodekloud/simple-webapp 0 Docker 0 0
Docker Docker
6 Container 6 Container 6 Container
8
docker run –p 3306:3306 mysql 3
0
6
docker run –p 8306:3306 mysql Docker Host
docker run –p 8306:3306 mysql
RUN – Volume mapping
docker run mysql

docker stop mysql


docker rm mysql

Data
docker run –v /opt/datadir:/var/lib/mysql mysql /var/lib/mysql
/opt/datadir
MYSQL
Docker Container

Docker Host
Inspect Container
docker inspect blissful_hopper
[
{
"Id": "35505f7810d17291261a43391d4b6c0846594d415ce4f4d0a6ffbf9cc5109048",
"Name": "/blissful_hopper",
"Path": "python",
"Args": [
"app.py"
],
"State": {
"Status": "running",
"Running": true,
},

"Mounts": [],
"Config": {
"Entrypoint": [
"python",
"app.py"
],
},
"NetworkSettings": {..}
}
]
Container Logs
docker logs blissful_hopper
This is a sample web application that displays a colored background.
A color can be specified in two ways.

1. As a command line argument with --color as the argument. Accepts one of


red,green,blue,blue2,pink,darkblue
2. As an Environment variable APP_COLOR. Accepts one of
red,green,blue,blue2,pink,darkblue
3. If none of the above then a random color is picked from the above list.
Note: Command line argument precedes over environment variable.

No command line argument or environment variable. Picking a Random Color =blue


* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
docker
environment
variables
Environment Variables
app.py

import os
from flask import Flask

app = Flask(__name__)


color = "red"

@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

python app.py
Environment Variables
app.py
import os
from flask import Flask

app = Flask(__name__)


color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")
Environment Variables
app.py
import os
from flask import Flask

app = Flask(__name__)


color = os.environ.get('APP_COLOR')
"red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

export APP_COLOR=blue; python app.py


ENV Variables in Docker

app.py

import os
from flask import Flask

app = Flask(__name__)


os.environ.get('APP_COLOR')
color = "red"
@app.route("/")
def main():
print(color)
return render_template('hello.html', color=color)

if __name__ == "__main__":
app.run(host="0.0.0.0", port="8080")

simple-webapp-color
docker run -e APP_COLOR=blue
ENV Variables in Docker
docker run -e APP_COLOR=blue simple-webapp-color

docker run -e APP_COLOR=green simple-webapp-color

docker run -e APP_COLOR=pink simple-webapp-color


Inspect Environment Variable
docker inspect blissful_hopper
[
{
"Id": "35505f7810d17291261a43391d4b6c0846594d415ce4f4d0a6ffbf9cc5109048",
"State": {
"Status": "running",
"Running": true,
},

"Mounts": [],
"Config": {
"Env": [
"APP_COLOR=blue",
"LANG=C.UTF-8",
"GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D",
"PYTHON_VERSION=3.6.6",
"PYTHON_PIP_VERSION=18.1"
],
"Entrypoint": [
"python",
"app.py"
],
}
]
d o c k e r

images
What am I containerizing?
How to create my own image?
Dockerfile

FROM Ubuntu 1. OS - Ubuntu


RUN apt-get update
RUN apt-get install python 2. Update apt repo

RUN pip install flask 3. Install dependencies using apt


RUN pip install flask-mysql

COPY . /opt/source-code
4. Install Python dependencies using pip

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run 5. Copy source code to /opt folder

6. Run the web server using “flask” command

docker build Dockerfile –t mmumshad/my-custom-app

docker push mmumshad/my-custom-app Docker


Registry
Dockerfile
Dockerfile

INSTRUCTION ARGUMENT

Dockerfile
Start from a base OS or
FROM Ubuntu another image

RUN apt-get update


RUN apt-get install python
Install all dependencies
RUN pip install flask
RUN pip install flask-mysql

COPY . /opt/source-code Copy source code

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run Specify Entrypoint


Layered architecture
Dockerfile docker build Dockerfile –t mmumshad/my-custom-app

FROM Ubuntu Layer 1. Base Ubuntu Layer 120 MB

RUN apt-get update && apt-get –y install python


Layer 2. Changes in apt packages 306 MB
RUN pip install flask flask-mysql
Layer 3. Changes in pip packages 6.3 MB
COPY . /opt/source-code
Layer 4. Source code 229 B
ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run
Layer 5. Update Entrypoint with “flask” command 0B
Docker build output
failure
docker build Dockerfile –t mmumshad/my-custom-app

Layer 1. Base Ubuntu Layer

Layer 2. Changes in apt packages


Layer 3. Changes in pip packages

Layer 4. Source code


Layer 5. Update Entrypoint with “flask” command
What can you containerize?

Containerize Everything!!!
docker

CMD
vs
ENT RY POINT
docker run ubuntu

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
45aacca36850 ubuntu "/bin/bash" 43 seconds ago Exited (0) 41 seconds ago
docker run ubuntu [COMMAND]

docker run ubuntu sleep 5

5
4
3
2
1
FROM Ubuntu

CMD sleep 5

CMD command param1 CMD sleep 5


CMD [“command”, “param1”] CMD [“sleep”, “5”] CMD [“sleep 5”]

docker build –t ubuntu-sleeper .


5
4
3
2
1
docker run ubuntu-sleeper
FROM Ubuntu
docker run ubuntu-sleeper sleep 10

CMD sleep 5
Command at Startup: sleep 10

FROM Ubuntu
docker run ubuntu-sleeper 10
10
sleep
ENTRYPOINT [“sleep”]

Command at Startup:
docker run ubuntu-sleeper
sleep: missing operand
Try 'sleep --help' for more information.

Command at Startup:
FROM Ubuntu docker run ubuntu-sleeper
sleep: missing operand
Try 'sleep --help' for more information.
ENTRYPOINT [“sleep”]
sleep

CMD [“5”]
5

Command at Startup:

10
docker run ubuntu-sleeper 10

Command at Startup:

sleep2.0 10
docker run --entrypoint sleep2.0 ubuntu-sleeper 10

Command at Startup:
d o c k e r

networking
Default networks
Bridge none host

docker run ubuntu docker run Ubuntu –-network=none docker run Ubuntu --network=host

5000 5000

Web Web Web Web


Container Container
Container Container
172.17.0.2 172.17.0.3
172.17.0.1
docker0
Web
Container
172.17.0.4 172.17.0.5

Web Web
Container Container

Docker Host Docker Host Docker Host


User-defined networks

docker network create \


Web Web –-driver bridge \
Container Container
-–subnet 182.18.0.0/16
172.17.0.2 182.18.0.3
172.17.0.3 custom-isolated-network
172.17.0.1 182.18.0.1
docker0 docker0

172.17.0.4 172.17.0.5
182.18.0.2 docker network ls

Web Web
Container Container

Docker Host
Inspect Network
docker inspect blissful_hopper
[
{
"Id": "35505f7810d17291261a43391d4b6c0846594d415ce4f4d0a6ffbf9cc5109048",
"Name": "/blissful_hopper",
"NetworkSettings": {
"Bridge": "",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.6",
"MacAddress": "02:42:ac:11:00:06",
"Networks": {
"bridge": {
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.6",
"MacAddress": "02:42:ac:11:00:06",
}
}
}
]
Embedded DNS

Host IP
mysql.connect( 172.17.0.3
mysql ) web mysql web 172.17.0.2
Container Container
172.17.0.2 172.17.0.3 mysql 172.17.0.3
docker0

DNS
Server

127.0.0.11

Docker Host
d o c k e r

storage
File system
/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

COPY . /opt/source-code COPY app2.py /opt/source-code

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask ENTRYPOINT FLASK_APP=/opt/source-code/app2.py flask


run run

docker build Dockerfile –t mmumshad/my-custom-app docker build Dockerfile2 –t mmumshad/my-custom-app-2

Layer 1. Base Ubuntu Layer 120 MB Layer 1. Base Ubuntu Layer 0 MB

Layer 2. Changes in apt packages 306 MB Layer 2. Changes in apt packages 0 MB

Layer 3. Changes in pip packages 6.3 MB Layer 3. Changes in pip packages 0 MB

Layer 4. Source code 229 B Layer 4. Source code 229 B

Layer 5. Update Entrypoint 0B Layer 5. Update Entrypoint 0B


Layered architecture

Read Write
Container Layer
Layer 6. Container Layer

docker run mmumshad/my-custom-app

Read Only
Layer 5. Update Entrypoint with “flask” command
Layer 4. Source code

Image Layers Layer 3. Changes in pip packages


Layer 2. Changes in apt packages
Layer 1. Base Ubuntu Layer

docker build Dockerfile –t mmumshad/my-custom-app


COPY-ON-WRITE

Read Write
Container Layer

temp.txt

Read Only

Image Layers app.py


volumes docker run –v data_volume:/var/lib/mysql mysql

docker volume create data_volume docker run –v data_volume2:/var/lib/mysql mysql

/var/lib/docker docker run –v /data/mysql:/var/lib/mysql mysql

volumes docker run \


–-mount type=bind,source=/data/mysql,target=/var/lib/mysql mysql
data_volume

Read Write Read Write

/var/lib/mysql /var/lib/mysql

mysql-container layer mysql-container layer

data_volum
e mysql

/var/lib/docker/volumes /data

Read Only
mysql – image layer
Docker Host
Storage drivers
• AUFS
• ZFS
• BTRFS
• Device Mapper
• Overlay
• Overlay2
d o c k e r

compose
Docker compose Public Docker registry - dockerhub
docker run mmumshad/simple-webapp

docker run mongodb


docker run redis:alpine

docker run ansible

docker-compose.yml
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

docker run -d --name=vote –p 5000:80 --link


voting-app
redis:redis

docker run -d --name=result –p 5001:80 --link db:db


result-app in-memory DB db
docker run -d --name=worker worker
--link db:db --link redis:redis

worker

! Deprecation Warning
Docker compose - build
docker-compose.yml docker-compose.yml
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
docker-compose.yml docker-compose.yml docker-compose.yml

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

version: 1 version: 2 version: 3


Docker compose
docker-compose.yml
version: 2
services:
redis: front-end
image: redis
voting-app result-app
networks:
- back-end
db:
image: postgres:9.4
networks:
- back-end
vote:
image: voting-app redis db
networks:
back-end
- front-end
- back-end
result:
image: result
networks:
- front-end worker
- back-end
networks:
front-end:
back-end:
d o c k e r

registry
Image

docker run nginx


docker.io
Docker Hub

Image

image: docker.io/ nginx/nginx

Registry User/ Image/


Account Repository
gcr.io/ kubernetes-e2e-test-images/dnsutils
Private Registry
docker login private-registry.io
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to
https://hub.docker.com to create one.
Username: registry-user
Password:
WARNING! Your password will be stored unencrypted in /home/vagrant/.docker/config.json.

Login Succeeded

docker run private-registry.io/apps/internal-app


Deploy Private Registry
docker run -d -p 5000:5000 --name registry registry:2

docker image tag my-image localhost:5000/my-image

docker push localhost:5000/my-image

docker pull localhost:5000/my-image

docker pull 192.168.56.100:5000/my-image


d o c k e r

engine
Docker Engine
Docker Engine Laptop

Docker CLI

REST API

Docker Deamon docker –H=remote-docker-engine:2375

docker –H=10.123.2.1:2375 run nginx


containerization
Unix
Process ID
Timesharing

Network Namespace Mount

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

Docker Docker Docker


Container Container Container

CPU Memory

docker run --cpus=.5 ubuntu

docker run --memory=100m ubuntu


d o c k e r

On Windows
Docker on windows
1. Docker on Windows using Docker Toolbox
2. Docker Desktop for Windows
1. Docker toolbox
• 64-bit operating
• Windows 7 or higher.
• Virtualization is enabled

• Oracle Virtualbox
• Docker Engine
• Docker Machine
• Docker Compose
• Kitematic GUI
2. Docker Desktop for Windows

Support: Windows 10 Enterprise/Professional Edition


Windows Server 2016

Linux Containers (Default)


Or
Windows Containers
Windows containers
Container Types:

Windows Server Hyper-V Isolation

Container Container Container


Container Container Container
Kernel Kernel Kernel

Kernel Kernel

Base Images:

• Windows Server Core

• Nano Server

Support
• Windows Server 2016
• Nano Server
• Windows 10 Professional and Enterprise (Hyper-V Isolated
Containers)
VirtualBox Or Hyper-V
d o c k e r

On Mac
Docker on Mac
1. Docker on Mac using Docker Toolbox
2. Docker Desktop for Mac
1. Docker toolbox
• macOS 10.8 “Mountain Lion” or newer

• Oracle Virtualbox
• Docker Engine
• Docker Machine
• Docker Compose
• Kitematic GUI
2. Docker Desktop for Mac

Support: macOS Sierra 10.12 or newer


Mac Hardware - 2010 model or newer

Linux Containers
container
orchestration
Why Orchestrate? Public Docker registry - dockerhub

docker run nodejs

docker run nodejs

docker run nodejs

docker run nodejs


Container Orchestration
docker service create -–replicas=100 nodejs
Container Orchestration
docker service create -–replicas=100 nodejs
d o c k e r
swarm
Solutions

Docker Swarm
Docker swarm

Docker Swarm

Web Web Web Web Web


Container Container Container Container Container

MySQL
Container

Docker Host Docker Host Docker Host Docker Host


Setup swarm
Node Node Node
Swarm Manager Worker Worker Worker

docker swarm init docker swarm join docker swarm join docker swarm join
--token <token> --token <token> --token <token>

Docker Host Docker Host Docker Host Docker Host


Docker service
docker service create -–replicas=3 –-network frontend my-web-server

docker service create -–replicas=3 –p 8080:80 my-web-server

docker run my-web-server docker service create -–replicas=3 my-web-server

Web Server Web Server Web Server


Web Server

Docker Host Worker Node Worker Node Worker Node

Docker Swarm
kubernetes
kubectl rolling-update my-web-server --rollback

kubectl rolling-update my-web-server --image=web-server:2

kubectl scale -–replicas=2000 my-web-server

docker run my-web-server kubectl run -–replicas=1000 my-web-server

A B

Docker Host Node Node Node

Kubernetes Cluster

Security POD AutoScalers Cluster AutoScalers

Network
Storage
Nodes (Minions)

Node
Cluster

Node Node Node


Master

Master Node Node Node


Components

Container
API Key-value store
Controller
Scheduler
kubelet
Kube
etcd
Runtime
Server
Master vs Worker Nodes

</> kube-apiserver </> kubelet

etcd

controller

scheduler
Container Runtime

Worker Node CRI-O


Master
kubectl

kubectl run hello-minikube

kubectl cluster-info

kubectl get nodes

kubectl run my-web-app --image=my-web-app --replicas=100


CONCLUSION
www.kodekloud.com
THANK YOU

You might also like