Slide di introduzione su docker. Scritte in markdown per reveraljs.

Argomenti trattati:

  • introduzione
  • caratteristiche
  • pregi
  • confronto con macchine virtuali
  • container
  • immagini
  • Dockerfile
  • docker-compose
## Slide in Markdown

Di seguito il file .md della presentazione.

\# docker
###An uncompleted introduction to docker
!\[text\](md/image/homepage-docker-logo.png)
####piuma@piumalab.org
---
## What is?
Docker is a platform for developers and sysadmins to develop,
 ship, and run applications.
---
## Why it was born?

To resolve a necessity

Mobility workload in cloud systems!
---
### Cargo transport pre-1960
!\[text\](md/image/cargo-transport-pre-1960.png)
---
### Solution: Intermodal Shipping Container
!\[text\](md/image/standard\_container.jpg)
---
### Docker is a Container System for Code
!\[text\](md/image/container.png)

Docker leverages LXC (Linux Containers), which encompasses Linux
features like cgroups and namespaces for strong process isolation and
resource control.

They are lightweight and consume less resources than a virtual machine.
---
## Benefits for developers
 - portability, build once... run anywhere
 - no worries about missing dependencies, packages and other pain
 points during subsequent deployments
 - tracking changes
 - run each app in its own isolated container, so you can run various
 versions of libraries and other dependencies for each app without
 worrying
 - reduce/eliminate concerns about compatibility on different
 platforms, either your own or your customers
---
## Benefits for sysadmins
 - portability, configure once... run anywhere
 - tracking changes
 - simple to understand what application do
 - simplify to upgrade application processes. Significantly improves
 the speed and reliability of continuous deployment and continuous
 integration systems
 - eliminate inconsistencies between different enviroments (develop, testing, production)
 - re-use other people images
 - do you not need an hypervisor. Because the containers are so
 lightweight, address significant performance, costs, deployment, and
 portability issues normally associated with VMs
---
## Docker Concepts and Interactions
 - \*\*Host\*\*, the machine that is running the containers.
 - \*\*Image\*\*, a hierarchy of files, with meta-data for how to run a container.
 - \*\*Container\*\*, a contained running process, started from an image.
 - \*\*Registry\*\*, a repository of images.
 - \*\*Volume\*\*, storage outside the container.
 - \*\*Dockerfile\*\*, a script for creating images.
-
!\[text\](md/image/docker-interactions.png)
---
## Separation of concerns
 - inside the container:
   \* libreries
   \* package manager
   \* application
   \* data
   \* code
 - outside the container:
   \* logging
   \* remote access
   \* network configuration
   \* monitoring
---
## Difference between docker and virtual machine
!\[text\](md/image/VM-Diagram.png)
---
## Dockerizing Applications
\`\`\`
$ docker run busybox /bin/echo 'Hello world'
\`\`\`
\`\`\`
$ docker run -t -i ubuntu:14.04 bash
\`\`\`
---
## Containers
\`\`\`
$ docker create  # creates a container but does not start it.
$ docker run     # creates and starts a container.
$ docker stop    # stops it.
$ docker start   # will start it again.
$ docker restart # restarts a container.
$ docker rm      # deletes a container.
$ docker kill    # sends a SIGKILL to a container.
$ docker attach  # will connect to a running container.
$ docker wait    # blocks until container stops.
$ docker exec    # executes a command in a running container.
\`\`\`
inspecting containers
\`\`\`
$ docker ps      # shows running containers.
$ docker inspect # information on a container (incl. IP address).
$ docker logs    # gets logs from container.
$ docker events  # gets events from container.
$ docker port    # shows public facing port of container.
$ docker top     # shows running processes in container.
$ docker diff    # shows changed files in container's FS.
$ docker stats   # shows metrics, memory, cpu, filsystem
\`\`\`
---
## Images
### like template for VMs
Docker leverages a copy-on-write fs. This allows Docker to instantiate
containers very quickly. Docker use to layering one container on top
of another. For example, you might create a container that is based on
a base Debian image, and then in turn create another container that is
based on the first container.
-
## Images
!\[text\](md/image/docker-filesystems-debian.png)
-
## Images
!\[text\](md/image/docker-filesystems-debianrw.png)
-
## Images
!\[text\](md/image/docker-filesystems-multilayer.png)
-
## Commands for interacting with images
\`\`\`
$ docker images  # shows all images.
$ docker import  # creates an image from a tarball.
$ docker build   # creates image from Dockerfile.
$ docker commit  # creates image from a container.
$ docker rmi     # removes an image.
$ docker history # list changes of an image.
\`\`\`
---
## Dockerfile
\`\`\`
FROM debian:7.8
MAINTAINER Piuma "piuma@piumalab.org"
RUN apt-get update && apt-get -y install apache2
EXPOSE 80
CMD \["/usr/sbin/apache2ctl", "-D", "FOREGROUND"\]
\`\`\`
\`\`\`
$ docker build -t apache-example .
\`\`\`
---
## docker-compose
Compose is a tool for defining and running complex applications with
Docker.

With Compose, you define a multi-container application in a
single file, then spin your application up in a single command which
does everything that needs to be done to get it running.
-
## docker-compose
###Using Compose is basically a three-step process:

 - \*\*First\*\*, you define your app's environment with a Dockerfile
 - \*\*Next\*\*, you define the services that make up your app in
 docker-compose.yml so they can be run together in an isolated
 environment.
 - \*\*Lastly\*\*, run docker-compose up and Compose will start and run your
 entire app.
-
## docker-compose
docker-compose.yml
\`\`\`
web:
  build: .
  command: python app.py
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  links:
   - redis
redis:
  image: redis
\`\`\`
\`\`\`
$ docker-compose up -d
\`\`\`
---
## docker-compose example
\`\`\`
web1:
  image: piuma/phpsysinfo
  ports:
   - "80:80"
\`\`\`
-
## docker-compose example
\`\`\`
web1:
  image: piuma/phpsysinfo
web2:
  image: piuma/phpsysinfo
proxy:
  image: tutum/haproxy
  links:
   - web1
   - web2
  ports:
   - "80:80"
\`\`\`
-
## docker-compose example
\`\`\`
web1:
  image: piuma/phpsysinfo
web2:
  image: piuma/phpsysinfo
web3:
  image: piuma/phpsysinfo
proxy:
  image: tutum/haproxy
  links:
   - web1
   - web2
   - web3
  ports:
   - "80:80"
\`\`\`
-
## docker-compose example
\`\`\`
phpmyadmin:
  image: nazarpc/phpmyadmin
  links:
   - mysql
  ports:
   - "8080:80"
mysql:
  image: mysql
  environment:
   - MYSQL\_ROOT\_PASSWORD=secret
\`\`\`
---
## What next?
From here, the logical step would be to scale our architecture by
creating a \*\*Docker Swarm\*\* cluster.
!\[text\](md/image/SWARM.png)
---
## Even this presentation runs in a docker container
\`\`\`
docker run -d -p 8000:8000 \\
           -v ~/documents/docker:/revealjs/md amouat/revealjs
\`\`\`
-
\`\`\`bash
docker run --rm mribeiro/cowsay "Any questions?"
 \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
< Any questions? >
 ----------------
        \\  ^\_\_\_^
         \\ (ooo)\\\_\_\_\_\_\_\_
           (\_\_\_)\\       )\\/\\
                ||----w |
                ||     ||
\`\`\`
---
## Exercises
 1. Building images with \*Dockerfiles\* 

 1. Using \*Supervisor\* with Docker

\*Supervisor\* is a \`\`process management tool\`\` to manage multiple processes in our container

 1. Automated Builds on Docker Hub

Automatically create images from a GitHub or Bitbucket repository containing a Dockerfile.

 1. Use \*docker-compose\* to benchmark a web server with ab

 1. Set up docker \*Swarm nodes\*

Docker Swarm is native clustering for Docker.

 1. Setup Docker Registry 2.0

Docker Registry stores and distributes images centrally.