introducing docker
TRANSCRIPT
#Outline
1 Virtualization
2 Containers
3 Docker in practice
4 Docker Compose
5 Continuous integration
Virtualization 2/24
Thinking about VMM
The Key component is the Hypervisor, a Virtual Machine Monitorthat can be thought as an API that provides access to the hw levelfor the VMs.
I Hosted ()I abstract guest operating
systems from the host one
I Bare Metal()I run directly on the host’s
hardware
VMware Workstation/Player, VirtualBox and QEMU are examplesof hosted hypervisors
Virtualization 3/24
Deep into Light Virtualization
Born on top of LXC project, a set of tools built on a userspaceinterface for the Linux kernel containment features, LV uses thefollowing kernel features to contain processes:
I Kernel namespaces (ipc, uts, mount, pid, network and user)
I Chroots (using pivot root)
I CGroups (control groups)
I Relies on your existingsystem;
I Services stay in the kernelhost;
Virtualization 4/24
Cgroups
Cgroups (abbreviated from control groups) is a Linux kernel featurethat limits, accounts for and isolates the resource usage (CPU,memory, disk I/O, network, etc.) of a collection of processes.
Cgroups provides:
I Resource Limiting: groups can be set to not exceed aconfigured memory limit
I Prioritization: some groups may get a larger share of CPUutilization or disk I/O
I Accounting: measures how much resources certain systemsuse
I Control: freezing the groups of processes, their checkpointingand restarting
Virtualization 5/24
Namespaces
Isolation
Groups of processes are separated so they cannot ”see” resourcesin other groups. For example, a PID namespace provides aseparate enumeration of process identifiers within each namespace.
struct upid {
int nr; // the PID value
// namespace where this PID is
relevant
struct pid_namespace *ns;
// ...
};
struct pid {
// number of upids
int level;
// array of upids
struct upid numbers [0];
};
Virtualization 6/24
The Layered Filesystem
Union file systems, or UnionFS, are file systems that operate bycreating layers, making them very lightweight and fast.
Copy-On-Write
It enables sharing that promotes smaller images
Virtualization 7/24
#Outline
1 Virtualization
2 Containers
3 Docker in practice
4 Docker Compose
5 Continuous integration
Containers 8/24
Why Containers?
Fast deployment time
It’s cheap and flexible
Scalability and support
Docker as standardized platform
Docker is a platform for developing, shipping,and running applications using containervirtualization technology.
Containers 9/24
The Docker environment
Containers 10/24
Docker: Terminology
Image: layered filesystem where each layer references the layerbelow
Dockerfile: build script that defines:I an existing image as starting pointI a set of instructions that augment that
image (each of which results in anotherlayered filesystem)
I metadata such as ports exposedI the command to executed when the
image is run
Container: runtime instance of an imageplus a read/write layer
Docker Hub: centralized repository of docker images
Containers 11/24
#Outline
1 Virtualization
2 Containers
3 Docker in practice
4 Docker Compose
5 Continuous integration
Docker in practice 12/24
Quick Start
I Linux - run natively e.g. on UbuntuI apt-get install docker.io
I curl -sSL https://get.docker.com/ubuntu — sh
I Mac / Windows run under VirtualBoxI http://boot2docker.io
I Docker Machine - https://github.com/docker/machineI docker machine -d virtual-box devI docker machine -d openstack test
I docker machine -d softlayer ... prod
Verify ..
$ docker versionClient/Server:Version: 1.9.1OS/Arch: linux/amd64
.. your installation
$ docker infoClient/Server:Version: 1.9.1OS/Arch: linux/amd64
Docker in practice 13/24
Quick Start
I Linux - run natively e.g. on UbuntuI apt-get install docker.io
I curl -sSL https://get.docker.com/ubuntu — sh
I Mac / Windows run under VirtualBoxI http://boot2docker.io
I Docker Machine - https://github.com/docker/machineI docker machine -d virtual-box devI docker machine -d openstack test
I docker machine -d softlayer ... prod
Verify ..
$ docker versionClient/Server:Version: 1.9.1OS/Arch: linux/amd64
.. your installation
$ docker infoClient/Server:Version: 1.9.1OS/Arch: linux/amd64
Docker in practice 13/24
Quick Start
I Linux - run natively e.g. on UbuntuI apt-get install docker.io
I curl -sSL https://get.docker.com/ubuntu — sh
I Mac / Windows run under VirtualBoxI http://boot2docker.io
I Docker Machine - https://github.com/docker/machineI docker machine -d virtual-box devI docker machine -d openstack test
I docker machine -d softlayer ... prod
Verify ..
$ docker versionClient/Server:Version: 1.9.1OS/Arch: linux/amd64
.. your installation
$ docker infoClient/Server:Version: 1.9.1OS/Arch: linux/amd64
Docker in practice 13/24
Quick Start
I Linux - run natively e.g. on UbuntuI apt-get install docker.io
I curl -sSL https://get.docker.com/ubuntu — sh
I Mac / Windows run under VirtualBoxI http://boot2docker.io
I Docker Machine - https://github.com/docker/machineI docker machine -d virtual-box devI docker machine -d openstack test
I docker machine -d softlayer ... prod
Verify ..
$ docker versionClient/Server:Version: 1.9.1OS/Arch: linux/amd64
.. your installation
$ docker infoClient/Server:Version: 1.9.1OS/Arch: linux/amd64
Docker in practice 13/24
The Docker command line
I docker searchSearch for images in the docker hub
I docker pullGet a selected image from the docker hub
I docker imagesList all downloaded images
I docker runstart a container
I docker psList running images
I docker buildBuild an image from a Dockerfile
I docker start/stop/killContainers management
I docker rm/rmiRemove a container / image
Docker in practice 14/24
Run your first container
I $ docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATEDubuntu Ubuntu is a Debian-based Linux operating s... 3132 [OK] [OK]ubuntu-upstart Upstart is an event-based replacement for... 61 [OK] [OK]
I $ docker pull ubuntu:latest
latest: Pulling from library/ubuntu92ec6d044cb3: Downloading 34.57 MB/65.68 MBDigest: sha256:457b0587384bdhuis83290....6db5ae3934307c757c54Status: Downloaded newer image for ubuntu:latest
I $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu latest 6cc0fc2a5ee3 1 minutes ago 187.9 MBchef-server latest f3cd15749fa8 21 months ago 1.043 GB
I $ docker run -i -t ubuntu /bin/bash
root@e550480534b1:/# apt-get update && apt-get install -y nginx
Docker in practice 15/24
Run your first container
I $ docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATEDubuntu Ubuntu is a Debian-based Linux operating s... 3132 [OK] [OK]ubuntu-upstart Upstart is an event-based replacement for... 61 [OK] [OK]
I $ docker pull ubuntu:latest
latest: Pulling from library/ubuntu92ec6d044cb3: Downloading 34.57 MB/65.68 MBDigest: sha256:457b0587384bdhuis83290....6db5ae3934307c757c54Status: Downloaded newer image for ubuntu:latest
I $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu latest 6cc0fc2a5ee3 1 minutes ago 187.9 MBchef-server latest f3cd15749fa8 21 months ago 1.043 GB
I $ docker run -i -t ubuntu /bin/bash
root@e550480534b1:/# apt-get update && apt-get install -y nginx
Docker in practice 15/24
Run your first container
I $ docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATEDubuntu Ubuntu is a Debian-based Linux operating s... 3132 [OK] [OK]ubuntu-upstart Upstart is an event-based replacement for... 61 [OK] [OK]
I $ docker pull ubuntu:latest
latest: Pulling from library/ubuntu92ec6d044cb3: Downloading 34.57 MB/65.68 MBDigest: sha256:457b0587384bdhuis83290....6db5ae3934307c757c54Status: Downloaded newer image for ubuntu:latest
I $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu latest 6cc0fc2a5ee3 1 minutes ago 187.9 MBchef-server latest f3cd15749fa8 21 months ago 1.043 GB
I $ docker run -i -t ubuntu /bin/bash
root@e550480534b1:/# apt-get update && apt-get install -y nginx
Docker in practice 15/24
Run your first container
I $ docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATEDubuntu Ubuntu is a Debian-based Linux operating s... 3132 [OK] [OK]ubuntu-upstart Upstart is an event-based replacement for... 61 [OK] [OK]
I $ docker pull ubuntu:latest
latest: Pulling from library/ubuntu92ec6d044cb3: Downloading 34.57 MB/65.68 MBDigest: sha256:457b0587384bdhuis83290....6db5ae3934307c757c54Status: Downloaded newer image for ubuntu:latest
I $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu latest 6cc0fc2a5ee3 1 minutes ago 187.9 MBchef-server latest f3cd15749fa8 21 months ago 1.043 GB
I $ docker run -i -t ubuntu /bin/bash
root@e550480534b1:/# apt-get update && apt-get install -y nginx
Docker in practice 15/24
The Dockerfile
I Dockerfile instruct on how to build the image automatically
I Dockerfile syntax:
I FROM
I RUN
I ENV
I EXPOSE
I ADD
I CMD
$ docker build -t fmount/nginx .
$ docker run -d -p 80 –name mystaticwebsite -v$PWD/website:/var/www/html/website fmount/nginx nginx
Docker in practice 16/24
The Docker Hub
It provides a mechanism to share images in the docker-hub, arepository of shareable collection of tagged images
$ docker commit/login
Exercise: Be Social :DI Register in the Docker Hub
I Connect it to your Github and build
Docker in practice 17/24
#Outline
1 Virtualization
2 Containers
3 Docker in practice
4 Docker Compose
5 Continuous integration
Docker Compose 18/24
Get an app running in one command
#!/bin/python
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host="localhost" ,\
port =6379)
@app.route("/")
def hello():
redis.incr("hits")
return "I have been seen %s
times.\n"
% redis.get("hits")
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=
True)
requirements.txt
I flask package
I redis package
Docker Compose 19/24
Get an app running in one command
Steps to follow
I Write your Dockerfiles
I Build your containers
I Prepare your application
I Think about the infrastructure
I Compose in a Microservices fashion
Build and start the containers
$ docker-compose up
Docker Compose 20/24
#Outline
1 Virtualization
2 Containers
3 Docker in practice
4 Docker Compose
5 Continuous integration
Continuous integration 21/24
Use case: Continuous Integration
Continuous integration 22/24
Thank you! Questions?
More examples athttps://github.com/fmount/containers
Continuous integration 23/24
References
The Docker Bookwww.dockerbook.com
How2dockhttps://github.com/how2dock/docbook
Docker in Actionhttps://www.manning.com/books/docker-in-action
Official dochttps://docs.docker.com/
SlideShare Docker Channelhttp://www.slideshare.net/Docker/
Golang tour :Dhttps://tour.golang.org/
Continuous integration 24/24