Introductiontodocker 150107194310 Conversion Gate02
Introductiontodocker 150107194310 Conversion Gate02
Introductiontodocker 150107194310 Conversion Gate02
Introduction to
Docker
http://gianlucacosta.info/
Introduction
● VM-based virtualization is an overwhelmingly vast sector, rich in nuances
and featuring a wide variety of solutions
● On the other hand, Docker is a very recent and evolving technology,
surrounded by a vibrant, ever-changing ecosystem
● We are going to see a practical introduction to Docker, focusing on its
building blocks – images and containers - trying to grasp their very
essence, especially in relation to traditional virtualization, without any
claim of completeness
● After discussing Docker, we'll briefly see a simple but complete
distributed application demonstrating how to use Docker containers in
practice, side-by-side with a hypervisor creating a virtual network node
● Special thanks to Prof.ssa Anna Ciampolini of University of Bologna for
her kind interest in the project and for her valuable advice and
suggestions; special thanks to Ing. Arialdo Martini for making me
discover containerization and Docker
Virtual machines...
● In traditional virtualization, every virtual machine is an isolated
sandbox on top of a hypervisor (or VMM – Virtual Machine Monitor)
● This solution is excellent in a broad range of contexts, such as multi-
tenant services based on different operating systems
● It is the hypervisor itself that usually provides a complete abstraction
of the underlying architecture, enabling the execution of any
operating system within each VM
● This strategy, however, might impact on performances: despite
optimizations such as fast binary translation and virtualizable
architectures, hypervisors still require CPU work to orchestrate their
VMs
● What if – for example - we just needed sandboxing for our services
on the same operating system?
...and containers!
OS 1 OS 2
VMM OS
HW HW
What about security?
Client host 1
Service 1 Service 2
Docker client
Container Container
<repository>[:<tag>]
docker images
different lines actually might refer to the same hex id – because every
line shows a different image name
docker ps
docker ps -a
● docker rm <container>
MiniSum
A simple distributed and dockerized architecture
Brief introduction
● This simple use case demonstrates how to employ Docker to support a distributed application
in a virtualized environment
● More precisely, the software architecture is composed of:
– SumService, a text/plain REST service that sums the 2 integer values passed in the query
string of its /sum action
– SumClient, which is SumService's client, employing PortAgent to retrieve SumService's
port on SumService's host (that is different from SumService's port within SumService's
container!)
– PortAgent, another text/plain REST service whose /getPort action queries Docker's APIs
on SumService's host to ascertain the host port on which SumService is listening
● Each program is written in Go and resides in a dedicated container, as we are going to see
● Different layouts would have been equally possible, but we have chosen this strategy in order
to show a few interesting techniques - in particular, container linking and use of Docker with a
traditional, VM-based virtualization solution creating a virtual network node
● All the source code, for both the programs and the Docker images, is published on Github at:
https://github.com/giancosta86/MiniSum
● The Docker images are published on Docker Hub, under the related giancosta86/* repositories
Architectural overview
SumClient
4
SumService
SumClientContainer
1 3
SumServiceContainer
2
PortAgent
Docker Engine
portagent
Fedora (64-bit) virtual node -
inside VirtualBox
Docker Engine
Host - Xubuntu (64-bit)
Networking considerations
/sum?op1=num1&op2=num2
/getPort?
dockerHost=dh&dockerPort=dp&containerName=cn&containerPort=cp
where:
– dp is Docker's host – in our case, <fedoraIP>
– dockerPort is Docker's port – usually 2375
– containerName is the name of the container enclosing SumService (in our
case, it will be SumServiceContainer)
– containerPort is the port – inside the above container – on which
SumService is listening
● By calling the Docker APIs exposed by the Fedora host, and by parsing the
JSON response, PortAgent returns just the numeric value of the port – on the
Fedora host - on which SumService's container is listening, or an error string
SumClient
● Interactive program
● Reads PortAgent's host and port from its command line;
sensible defaults are provided in the related Docker image,
but they can be overridden when creating the container
● It starts by asking the user for the 4 parameters required
by PortAgent and calls it, showing errors until a valid
service port value is returned
● Then, it starts an interactive cycle requesting the 2
operands and directly calling SumService to retrieve a
result
Linking example
● SumClient's command line arguments default to:
portagent 7070
where 7070 is PortAgent's default port in the related image, but what
about portagent? How is that host name defined?
● It must be defined when creating SumClient's container, by adding the
following parameter to docker run:
--link portagent:portagent
● This way, portagent will always refer to the IP address of PortAgent's
container, even if the container gets restarted
● Of course, PortAgent's container must have already been created,
with the --name portagent parameter
Running PortAgent's container
● We'll assume that:
– The Docker Engine is already installed and listening on the
Xubuntu host
– The current user belongs to the docker group
● To create the container, type in Xubuntu's shell: