Docker: Rui Couto António Nestor Ribeiro

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Docker

Rui Couto
António Nestor Ribeiro
Outline

• What is docker

• Docker images

• Docker vs VMs/standalone

• An example of an image
What is docker

• Docker is a container platform.

• It eliminates “works on my machine” problem.

• Allows the development of applications based on


containers.

• Containers run side by side.


What is a container

• Self contained units (similar to virtual machines).

• Run on top of docker, isolated from the operating


system.

• Contrary to virtual machines, pack only the required


dependencies.

• Have the same behaviour, despite the target platform


(similar to Java applications).
Containers
• Container images are lightweight and stand-alone.

• Include code, runtime, system tools, system libraries, settings.

• Help to reduce conflicts between teams running different software on the


same infrastructure.

• Applications are built by combining


different containers.
Containers vs VMs
• Virtual machines require the full operating system stack.

• Containers required only the libraries and applications.

• Runtimes and other dependencies can be shared across


different containers.
Containers vs Native
applications

• Containers are rapidly becoming the industry


standard.

• Docker is highly scalable.


A docker image

• Is composed of two main components:

• The application itself (plus libraries, configs, etc);

• A Dockerfile

• The Dockerfile describes the dependencies of the


container.

• Describes also how to deploy the application.


Example
• Structure of container to run a Java web application

Dockerfile WAR

• Dockerfile:
FROM jboss/wildfly
ADD WebApp1.war /opt/jboss/wildfly/standalone/deployments/
Example
• Interactions with docker are performed via shell.

• Images need to be created (i.e. compiled) before


running them.

• The docker build command builds and makes the


image available.
$ docker build --tag=app_name .
Sending build context to Docker daemon 5.632 kB
Step 1/2 : FROM jboss/wildfly
---> d4b4d01b53bd
Step 2/2 : ADD App.war /opt/jboss/wildfly/standalone/deployments/
---> 6a4f07aca46e
Removing intermediate container 829a24a5d6ab
Successfully built 6a4f07aca46e
Example
• Docker images can then be run.

• The docker run command has several customisation


options, such as ports.
$ docker run -p 80:8080 -it app1
Apache mod_proxy
Outline

• Introduction

• Configuration

• Example
Introduction

• mod_proxy is a proxy module for the Apache HTTP


server.

• It implements routing features as well as load


balancing.

• It is bundled with apache by default.


Introduction
• With mod_proxy, a machine can be easily configured
to be the load balancer.

• The process is transparent to the user.

192.168.1.10
Machine 1

192.168.1.11
Apache Machine 2
Client
(w/mod_proxy)

193.136.19.80
192.168.1.N
Machine N
Configuration
• mod_proxy is enabled and configured in the apache
configuration file.
LoadModule proxy_module libexec/apache2/mod_proxy.so
...
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid
...
ProxyPassReverse / http://localhost:8080/
...

<Proxy balancer://mycluster/>
BalancerMember http://<url> ... loadfactor=A
...
</Proxy>
Example
• Two docker containers wit Java web applications were
deployed in ports 8282 and 8383.
Example
• Apache was configured to route requests on / to both
addresses.
<Proxy balancer://mycluster/>
BalancerMember http://localhost:8282/WebApp1 route=node1 retry=60 loadfactor=80
BalancerMember http://localhost:8383/WebApp2 route=node2 retry=60 loadfactor=20
</Proxy>
Example
• For a significative number of requests , it is possible to
see that the load is being balanced.
Docker
Rui Couto
António Nestor Ribeiro

You might also like