Build, ship & run apps everywhere
Containers
Containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server.
This guarantees that it will always run the same, regardless of the environment it is running in.
Containers vs. VMs
- Opensource project with +1100 contributors
- Released on March 2013
- Written in Go
- Automates deployments
-
Run processes in isolation using linux virtualization features
- lxc, cgroups, unionfs, kernel namespaces
- libcontainer replaced lxc including several performance improvements
Docker
Docker Architecture
Images & containers
Images
Are read-only templates
Composed by layers using Union File System
Parent image + new layers
Containers
User added files
Metadata
UnionFS + namespaces + cgroups
Image + new read-write layer
Let's run a container
Pulls the ubuntu image from docker hub
Creates a new container
Allocates a filesystem and mounts a read-write layer
Allocates a network / bridge interface
Sets up an IP address
Executes a process that you specify
Captures and provides application output
docker run -i -t ubuntu /bin/bash
Dockerfile
FROM
ENV
ADD
COPY
WORKDIR
RUN
EXPOSE
VOLUME
USER
CMD
ONBUILD
example
Multiple containers?
Docker compose
A tool to compose and run multiple isolated environments on a single host using docker containers
- Development environments
- Automated testing environments
- Not recommended for production yet
Hands on
nginx
django
redis
postgres
data
web:
restart: always
build: ./web
expose:
- "8000"
links:
- postgres:postgres
- redis:redis
volumes:
- /usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn docker_django.wsgi:application -w 2 -b :8000
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- /www/static
volumes_from:
- web
links:
- web:web
postgres:
restart: always
image: postgres:latest
volumes_from:
- data
ports:
- "5432:5432"
redis:
restart: always
image: redis:latest
ports:
- "6379:6379"
data:
restart: always
image: postgres:latest
volumes:
- /var/lib/postgresql
Docker Machine
Manage local and remote docker hosts
- Needed on Windows and OSX machines
- Supports most VM Systems and Cloud Hosting Providers
- VirtualBox, VMWare, Softlayer, Hyper-V
- AWS, Azure, DigitalOcean, Rackspace, Google, Exoscale
docker-machine create -d virtualbox dev;
eval "$(docker-machine env dev)"
docker-machine ls
New docker machine
docker-compose build
docker-compose up -d
docker-compose run web /usr/local/bin/python manage.py migrate
git clone git@git.sophilabs.io:ssassi/test-docker-django.git
Clone repo, build it and run it!
docker ps -a
Kitematic
a GUI for lazies
Scalability & Availability
Cluster Managers
cluster managers war
Docker Swarm
Official clustering solution for docker, including scheduling, scalability and availability management
- Is under development
- Master-slave design
- Multiple discovery backends
- static file
- etcd
- consul
- zookeeper
- Multiple scheduling strategies and rules
- Hosts can be created on any cloud hosting provider
Swarm Strategies
Strategies for containers allocation on available hosts
-
random
- chooses a random host
-
spread
- prefers the hosts with less containers running
-
binpack
- prefers the hosts with most containers running
Swarm Scheduling
Available filters for containers allocation on available hosts
-
constraint
- assign tags to hosts and then filter by them
-
affinity
- require that container runs next to another one
-
port
- requires that a specific port is available
-
dependency
- collocates dependent containers by resources sharing
-
health
- avoid unhealthy nodes
docker-machine create -d virtualbox --swarm --swarm-master --swarm-discovery token://08c73c596622ad6010d22ad4ec043ca7 swarm-master
Let's create a cluster
master
slave nodes
docker-machine create -d virtualbox --swarm --swarm-discovery token://08c73c596622ad6010d22ad4ec043ca7 swarm-agent-00
docker-machine create -d virtualbox --swarm --swarm-discovery token://08c73c596622ad6010d22ad4ec043ca7 swarm-agent-01
eval $(docker-machine env --swarm swarm-master)
...adding a new container
get info
slave nodes
docker run hello-world
docker info
docker ps -a
Docker containers
Dockerfile
Docker hub
Kitematic
Docker compose
Docker machine
Docker swarm
Summary
Thanks
docker
By Sebastián Sassi
docker
- 1,256