Containerization
Advanced Software Development Methodologies
(DAC - Oct 2021)
vigneswaris@[Link]
Overview
❏ Introduction to Containerization
❏ Containers & Docker
❏ Architecture
❏ Deployment & Scaling
❏ Orchestration
❏ Hands-on - Creation of containers
2
Introduction to Containerization
Evolution of Computing
4
Containerization
❏ Light weight OS level sandboxing of applications
Runs multiple isolated apps on single host without hypervisor
❏ Currently, the hottest trend in datacenter innovation
Next step for optimizing computing resources post Vms
❏ Build and configure once, run anywhere
Ideal for DevOps and modern micro-services architectures
❏ Significant buy-in from both start-ups and large vendors
Packaged Software:MySQL, MongoDB, Redis, NodeJS
OS Vendors:Microsoft, Apple, Red Hat, SUSE, CoreOS
Clouds: Amazon, Microsoft, IBM, Rackspace, Google
Major Users: Netflix, Paypal, eBay, Google, Spotify
5
Containerization: A Step beyond Virtualization
6
Need for Containerization
Virtualization - Pros & Cons
❏ Abstraction to Hardware
❏ Isolation
❏ Encapsulation
❏ Portability
❏ Software Updates
❏ Continuous Integration & Continuous Delivery
7
Comparison
8
Containers
9
Why Containers?
10
Containers
11
Docker
❏ Docker is an open platform for developing, shipping, and
running applications. Docker Engine follows client-server
architecture.
12
13
Docker Internals
14
Docker Components
Docker Daemon
❏ The Docker daemon (dockerd) listens for Docker API
requests and manages Docker objects such as images,
containers, networks, and volumes.
❏ A daemon can also communicate with other daemons to
manage Docker services.
15
Docker Components
Docker Client
❏ Docker client (docker) is the primary way that many Docker
users interact with Docker.
❏ docker run - the client sends these commands to dockerd,
which carries them out.
❏ Docker client can communicate with more than one daemon.
16
Docker Components
Docker Registries
❏ A Docker registry stores Docker images.
❏ Docker Hub and Docker Cloud are public registries
❏ Default – Docker Hub
❏ Private Registry
17
Docker Components
Docker Objects
Images
❏ An image is a read-only template with instructions for
creating a Docker container.
❏ An image is based on another image.
❏ To build your own image, create a Dockerfile with a simple
syntax for defining the steps needed to create the image and
run it.
❏ Each instruction in a Dockerfile creates a layer in the image
18
Docker Components
Docker Objects
Containers
❏ A container is a runnable instance of an image.
❏ You can create, start, stop, move, or delete a container using
the Docker API or CLI.
❏ By default, a container is relatively well isolated from other
containers and its host machine.
19
Docker Components
Docker Objects
Network
20
Docker Components
Docker Objects
Volumes
21
Dockerfile, Images & Containers
22
Dockerfile, Images & Containers
❏ Docker containers are building blocks for applications.
❏ Each container is an image with a readable/writeable layer on
top of a bunch of read-only layers.
❏ These layers are also called intermediate images.
❏ Layers are generated when the commands in the Dockerfile
are executed during the Docker image build.
23
Layers
24
Shared Layering
25
Container Deployments
26
Scaling
Reactive & Predictive/ Proactive Scaling
27
Horizontal Scaling (Reactive)
28
Vertical Scaling (Reactive)
29
Proactive Scaling
❏ Changing availability of resources are difficult to predict, is
complex.
❏ A promising approach to handle such dynamics is
self-adaptation that can be realized by a MAPE-K feedback
loop
❏ Monitor-Analyze-Plan-Execute plus Knowledge
30
Proactive Scaling
31
Prediction Techniques
❏ Prediction using ML Techniques
❏ Linear Regression
❏ Support Vector Machine
❏ Artificial Neural Network
❏ Reinforcement Learning (RL)
❏ Autoregressive integrated moving average (ARIMA)
❏ Hidden Markov Model (HMM)
❏ Exponential Smoothening 32
Scaling Options
❏ RR
Scaling-out:Reactive + Scaling-in: Reactive
❏ PR
Scaling-out: Predictive + Scaling-in: Reactive
❏ RP
Scaling-out: Reactive + Scaling-in: Predictive
❏ PP
Scaling-out: Predictive + Scaling-in: Predictive 33
Docker Orchestration
Kubernetes is an open source system for
managing containerized applications
across multiple hosts, providing basic
mechanisms for deployment,
maintenance, and scaling of applications.
Docker Swarm is a clustering and
scheduling tool for Docker containers.
With Swarm, IT administrators and
developers can establish and manage a
cluster of Docker nodes as a single virtual
system.
34
Working with Docker
Docker - Releases
36
Installation
❏ Uninstall old versions
❏ Install DOCKER CE
❏ docker-ce
❏ Verify the Installation
❏ docker run hello-world
37
Docker Commands
❏ docker info
❏ docker images
❏ docker search <image>
❏ docker pull
❏ docker run
❏ docker ps
❏ docker exec
38
Image Creation from a container
❏ docker container run -ti ubuntu bash
❏ apt-get update
❏ apt-get install -y figlet
❏ figlet "hello docker"
❏ docker container ls -a (In other terminal)
❏ docker container commit CONTAINER_ID
❏ docker image tag <IMAGE_ID> ourfiglet
❏ docker image ls -a
❏ docker container run ourfiglet figlet hello
39
Image Creation using a Dockerfile
❏ Example1 var os = require("os");
❏ Create a .js file var hostname = [Link]();
[Link]("hello from " + hostname);
FROM alpine
❏ Create Dockerfile RUN apk update && apk add nodejs
COPY . /app
WORKDIR /app
CMD ["node","[Link]"]
❏ docker image build -t hello:v0.1 .
❏ docker container run hello:v0.1
❏ docker image history <image ID>
❏ echo "[Link](\"this is v0.2\");" >> [Link]
❏ docker image build -t hello:v0.2 . 40
Image Creation using a Dockerfile
❏ Creating our own Base Image
❏ debootstrap bionic bionic > /dev/null
❏ tar -C bionic -c . | docker import - bionic
❏ Write DockerFile
❏ docker build
❏ docker run
❏ docker inspect
❏ docker push
❏ Docker image history <Image ID>
41
Docker Compose
❏ Compose is a tool for defining and running multi-container
Docker applications.
❏ Use a YAML file to configure your application’s services.
❏ Then, with a single command, you create and start all the
services from your configuration.
❏ apt-get install docker-compose
45
Docker Compose
Using Compose is basically a three-step process:
❏ Define your app’s environment with a Dockerfile so it can be
reproduced anywhere.
❏ Define the services that make up your app in
[Link] so they can be run together in an
isolated environment.
❏ Run docker-compose up and Compose starts and runs your
entire app.
46
Docker Compose
A [Link] looks like this:
47
Containers Vs Services
48
Handson
Multi Service App using docker
Deploy the database
docker run -d -e POSTGRES_USER=odoo -e
POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres
--name db postgres:10
Deploy ODOO
docker run -p 8069:8069 --name odoo --link db:db -t odoo
50
Multi Service App using docker-compose
[Link]
Ex: Wordpress
docker-compose up -d
51
Assignment
Docker Containers
❏ Creation of containers for multi service application using
docker.
❏ Creation of containers for multi service application using
docker-compose
53