Docker 1
Docker 1
Docker 1
Agenda
- Motivation: Shift from Monolithic to Microservices Architectures
- The problem solved by Docker
- How Docker is different from Virtual Machines
- Docker workflow: Build, Ship and Run
- Docker commands
- Hands-on exercise
Monolithic A Decade ago (and still valid)
- Apps were monolithic
Slowly-changing - Built on a single stack such as .NET or Java
- Long Lived
- Deployed to a single server
5
Customer/
Clients/ Users
Data
Today Storage
Data
Storage
Data
6 Storage
Once upon a time… A software stack
7
Now....much more distributed, complex...
8
9
10
An Effort to “host” different “stacks”...
11
(Every possible goods) x (Every possible way to ship)
12
A Solution…
13
Docker ~ Brings standardization on packaging stacks
14
Less Portable, More Portable,
Minimal Overhead Lots of Overhead
Configuration Tools
16
Less Portable, More Portable,
Minimal Overhead Lots of Overhead
Configuration Tools
17
Development workflow (without Docker)
Development workflow (without Docker)
Development workflow (without Docker)
Development workflow (without Docker)
Development workflow (with Docker)
Development workflow (with Docker)
Development workflow (with Docker)
What is Docker?
• A tool that can package an application and its dependencies in a virtual
container
• Implementation of a container which is portable using a concept of image
• Docker uses the host OS kernel, there is no custom or additional kernel inside
running containers
• Docker uses resource isolation features of the Linux kernel such as cgroups and
kernel namespaces to allow independent “containers” to run within a single Linux
instance, avoiding the overhead of starting virtual machines
29
A note on Linux namespaces
• Isolation for several aspects of processes and resources
• See for example: Process ID isolation
Processes in the child namespace do not see the parent process’s existence;
processes in the parent namespace have a complete view of processes in the child namespace
29
A note on Linux namespaces (cont.)
• Isolation for several aspects of processes and resources
• See for example: Process ID isolation
Processes in the child namespace do not see the parent process’s existence;
processes in the parent namespace have a complete view of processes in the child namespace
29
What is Docker?
• Standardized packaging for
software and dependencies
• Isolate apps from each other
• Share the same OS kernel
• Works for all major Linux
distributions
• Available for Windows
(Server, since 2016) and MacOS
30
VMs vs Docker - Differences
Virtual Machines Docker
Each VM runs its own OS All containers share the same kernel of
the host
Boot up time is in minutes Containers instantiate in seconds
VMs snapshots are used sparingly Images are built incrementally on top of
another like layers. Lots of
images/snapshots
Not effective diffs. Not version controlled Images can be diffed and can be version
controlled. Dockerhub is like GITHUB
Cannot run more than couple of VMs on Can run many Docker containers in a
an average laptop laptop.
Only one VM can be started from one set Multiple Docker containers can be started
of VMX and VMDK files from one Docker image
34
Containers versus VMs
Docker Engine
Creates, ships and runs Docker containers deployable on a physical or
virtual, host locally, in a datacenter or cloud service provider
WORKDIR $CATALINA_HOME
CMD
The main purpose of a CMD is to provide defaults for
an executing container.
Can be overridden with arguments to docker run
CMD ["catalina.sh", "run"]
Hands-on exercise
a) Install Docker (sudo apt install docker.io)
b) Create a folder, a bash script and a Dockerfile
c) Instruct the Dockerfile to execute the script at container startup
d) The script shold list the contents of “/” and place the result in a file
e) Build the image ( docker build -t image_name . )
f) Start a container based on the created image
g) Let us use “docker exec” to log in the container and show the results
h) Let us use “docker cp” to copy the output file into the host machine
Build, Ship & Run
Put it all together: Build, Ship, Run Workflow
Developers IT Operations
48
Docker Compose – Building Microservices in easy way
Backend Service
Specify Volumes/Network
Environmental variables
Frontend Service
Specify Volumes/Network
Environmental variables