Skip to content

Latest commit

 

History

History
881 lines (571 loc) · 24.2 KB

docker-intro.md

File metadata and controls

881 lines (571 loc) · 24.2 KB

Docker logo

Docker for Developers - Introduction

Labs Docker Cuba, 22 March 2017


--

Acknowledgements

Organizers of the Festival of Software UNISS (Thanks)

Based on slides for presentation in Python Meetup Thessaloniki, 15 April 2016


Who am I?

  • Chairman of SciPyLA 2017
    • Science + Python + Latin America
  • Maintainer of a few Trac plugins
  • Apache Bloodhound project
  • Python-Cuba WG, Python Software Foundation
  • Brython committer

--

Who I used to be?

  • Graduated from ISPJAE (CUJAE) ... few years ago
  • Fields of competence
    • Antivirus
    • TVC / ICRT
    • Programming (web, desktop, Android, Smart TV, wearables)
    • DevOps support

--

Who I used to be? (contd.)

  • Fields of competence (contd.)
    • Fieldbus (Modbus, DNP3, radio, CANbus, Profibus)
    • Big data (Apache Hadoop / Spark, Machine learning)
    • Makers
      • 3D printer, CNC, DRO
      • DIY (Raspberry Pi, Beaglebone Black, ODROID, MicroPython, Arduino)

Talk overview

  • History and background
  • Docker overview
  • Docker use cases
  • Understanding Docker
  • Docker examples
  • Docker ecosystem
  • Events coming soon

First contact with Docker - PyCon 2014

Intro to Docker - PyCon 2014


The origins

Future of Linux Containers - PyCon 2013 Docker in DjangoCon 2013
PyCon 2013 DjangoCon 2013

Docker History

  • Solomon Hykes (@solomonstre)
  • dotCloud (now Docker Inc)
  • March 2013
  • Apache 2.0 license
  • 30k stars on Github
  • 260k public repositories on hub.docker.com
  • Docker Inc acquires everyone TM
  • Docker joins the "Open Container Initiative", June 2015

What about today ?

DockerCon 2017 PyCon 2017
DockerCon 2017 PyCon 2017
5 tracks 4 tutorials / 4 talks
5,000 attendees 3,000 attendees

Docker Birthday #4

Docker Birthday #4


Let me ask you

  • Who knows about Docker?
  • Who uses Docker for development?
  • Who uses Docker in production?
  • Who tried but could not do it?

What is Docker (v17.03)

Docker is an open platform for developing, shipping, and running applications.

Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

--

Docker in ICT ecosystem

Virtualization


Docker vs VMs

Docker vs traditional Virtualization


Docker Benefits

  • Fast (deployment, migration, restarts)
  • Secure
  • Lightweight (save disk & CPU)
  • Open Source
  • Portable software
  • Microservices and integrations (APIs)
  • Simplify DevOps
  • Version control capabilities

--

Micro-what ? Services ?

Microservices architecture


Common Docker usages

  • Sandbox environment (develop, test, debug, educate)
  • Continuous Integration & Deployment
  • Scaling apps
  • Development collaboration
  • Infrastructure configuration
  • Local development
  • Multi-tier applications
  • PaaS, SaaS

--

Development environment

Development environment

--

Education JupyterHub software

JupyterHub

--

Education - JupyterHub deployment

JupyterHub components

--

Continuous integration

Continuous Integration with Docker

--

Continuous delivery - Joomla

Joomla Continuous Delivery

--

Scaling - from 10's to 1000's

Apache Mesos problem description

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - app server regions

Apache Mesos app server regions

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - ouch !

Apache Mesos email message

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - problem amplified

Apache Mesos - problem amplified

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - Utilization

Apache Mesos utilization

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - Cluster Manager

Apache Mesos architecture

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - Execution

Apache Mesos resource assignment

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Scaling - Apache Mesos supports Docker since 2014

Apache Mesos

Benjamin Hindman (Twitter) - DockerCon 2014 video

--

Containers in Google Cloud Platform

Google data center GCE supports Docker
  • Everything at Google runs in a container
  • +2 billion containers per week

--

Big data powered by Docker

BlueData Epic Platform


Joe Beda, Senior Staff Software Engineer, Google Cloud Platform
GlueCon - May 22, 2014

Technology behind Docker

--

Docker code written in Go

Docker and Go Golang Book

--

Linux namespaces

Linux namespaces

--

Resource allocation with cgroups

cgroups allocation example

--

Resource allocation with cgroups

cgroups allocation example


The Docker architecture

Docker architecture


Docker components

  • (Docker) client
  • daemon
  • engine
  • machine
  • compose
  • swarm
  • registry

Docker client

It is the primary user interface to Docker. It accepts commands from the user and communicates back and forth with a Docker daemon.


Docker daemon

Docker libs

It runs on a host machine. The user does not directly interact with the daemon, but instead through the Docker client with the RESTful api or sockets.


Docker engine

A Client with a Daemon as also as the docker-compose tool. Usually referred simply as "docker".


Docker machine

Docker machine logo

A tool which makes it really easy to create Docker hosts on your computer, on cloud providers and inside your own data center. It creates servers, installs Docker on them, then configures the client to talk to them.


Docker compose

Docker compose logo

A tool for defining and running complex applications with Docker (eg a multi-container application) with a single file.

--

Container orchestration example

Docker compose example


Docker swarm

Docker swarm logo

A native clustering tool for Docker. Swarm pools together several Docker hosts and exposes them as a single virtual Docker host. It scale up to multiple hosts.


Docker distribution

Docker distribution logo

A (hosted) service containing repositories of images which responds to the Registry API.


Steps of a Docker workflow

docker run -i -t -d ubuntu:15.04 /bin/bash

The docker image

Docker architecture ubuntu:15.04 image

The docker container

Docker architecture container using ubuntu:15.04 image

--

Union filesystem explained

UFS explained


The Dockerfile

A Dockerfile is a text document that contains all the commands a user could call on the command line to create an image.

--

Dockerfile for these slides

FROM bitnami/apache
MAINTAINER Olemis Lang <[email protected]>

# Add the whole repo.
ADD . /opt/bitnami/apache/htdocs/

# Set this as initial path when logging in via ssh.
WORKDIR /opt/bitnami/apache/htdocs/

--

Docker image trees

Docker image tree


Common Docker Commands

// General info
man docker // man docker-run
docker help // docker help run
docker info
docker version
docker network ls

// Images
docker images // docker [IMAGE_NAME]
docker pull [IMAGE] // docker push [IMAGE]

// Containers
docker run
docker ps // docker ps -a, docker ps -l
docker stop/start/restart [CONTAINER]
docker stats [CONTAINER]
docker top [CONTAINER]
docker port [CONTAINER]
docker inspect [CONTAINER]
docker inspect -f "{{ .State.StartedAt }}" [CONTAINER]
docker rm [CONTAINER]


Docker examples

  • SSH into a container
  • Build an image
  • Docker Volume
  • Linked containers
  • Using docker-compose
  • Scale containers with docker-compose
  • Share an image (share this presentation)
  • Package an app with its environment
  • Screen and sound within containers (x-forward)

--

Example: SSH into a container

docker pull ubuntu
docker run -it --name ubuntu_example ubuntu /bin/bash

--

Example: Run Jenkins standalone

Let's run the official jenkins image

docker pull jenkins

// Test it
docker run -d -p 8098:8080 --name jenkins_example_1 jenkins
// Open http://localhost:8098

--

Example: Build an Image

Let's build a jenkins image

cd ~/Docker-presentation
git clone [email protected]:komljen/dockerfile-examples.git.git
cd dockerfile-examples/jenkins
docker build -t jenkins-local .

// Test it
docker run -d -p 8099:8080 --name jenkins_example_2 jenkins-local
// Open http://localhost:8099

--

Example: Docker volume

Let's use Apache server

cd ~/Docker-presentation
mkdir apache-example
cd apache-example

docker pull bitnami/apache
docker run --name apache_volume_example \
           -p 8180:80 -p 443:443 \
           -v $(pwd):/opt/bitnami/apache/htdocs/ \
           -d bitnami/apache

// Locally create an index.html file
echo "It works using mount." >> index.html

// Open http://localhost:8180 to view the html file

--

Example : Drupal + MariaDB w/ network isolation

Bitnami offers preconfigured, zero-conf containers

docker pull bitnami/mariadb:latest bitnami/drupal:latest

docker network create drupal-tier
docker run -d --name mariadb --net drupal-tier bitnami/mariadb:latest
docker run -d -p 8081:80 -p 443:443 --name drupal --net drupal-tier bitnami/drupal:latest

--

Example: Docker link containers

Let's create a Drupal app (apache, php, mysql, drupal)

cd ~/Docker-presentation
mkdir drupal-link-example
cd drupal-link-example

docker pull drupal:8.0.6-apache
docker pull mysql:5.5

// Start a container for mysql
docker run --name mysql_example \
           -e MYSQL_ROOT_PASSWORD=root \
           -e MYSQL_DATABASE=drupal \
           -e MYSQL_USER=drupal \
           -e MYSQL_PASSWORD=drupal \
           -d mysql:5.5

// Start a Drupal container and link it with mysql
// Usage: --link [name or id]:alias
docker run -d --name drupal_example \
           -p 8280:80 \
           --link mysql_example:mysql \
           drupal:8.0.6-apache

// Open http://localhost:8280 to continue with the installation
// On the db host use: mysql

// There is a proper linking
docker inspect -f "{{ .HostConfig.Links }}" drupal_example

--

Example: Using Docker Compose

Let's create a Drupal app with docker-compose.yml

cd ~/Docker-presentation
git clone [email protected]:cubantech/docker-presentation.git
cd docker-presentation/examples/docker-compose

// Run docker-compose using the docker-compose.yml
cat docker-compose.yml
docker-compose up -d

--

Example: Share a public Image

cd ~/Docker-presentation
git clone [email protected]:cubantech/docker-presentation.git
cd docker-presentation

docker pull bitnami/apache
docker build -t olemis/docker-presentation .

// Test it
docker run -itd --name docker_presentation \
           -p 8480:80 \
           olemis/docker-presentation

// Open http://localhost:8480, you should see this presentation

// Push it on the hub.docker.com
docker push olemis/docker-presentation

--

Example: Export/Save/Load etc

docker pull nimmis/alpine-apache
docker run -d --name apache_example \
           nimmis/alpine-apache

// Create a file inside the container.
// See http://github.com/nimmis/docker-alpine-apache for details.
docker exec -ti apache_example \
            /bin/sh -c 'mkdir /test && echo "This is it." >> /test/test.txt'

// Test it. You should see message: "This is it."
docker exec apache_example cat /test/test.txt

// Commit the change.
docker commit apache_export_example myapache:latest

// Create a new container with the new image.
docker run -d --name myapache_example myapache

// You should see the new folder/file inside the myapache_example container.
docker exec myapache_example cat /test/test.txt

// Export the container as image
cd ~/Docker-presentation
docker export myapache_example > myapache_example.tar

// Import a new image from the exported files
cd ~/Docker-presentation
docker import myapache_example.tar myapache:new

// Save a new image as tar
docker save -o ~/Docker-presentation/myapache_image.tar myapache:new

// Load an image from tar file
docker load < myapache_image.tar

--

Example: GUI with Docker

See examples at hub.docker.com/u/jess

// Before staring we should grant access to everyone on the X Server (locally)
// Otherwise the containers below will never start and they will not be able to use x11
xhost +

// Libreoffice
docker run  -d \
            -v /etc/localtime:/etc/localtime:ro \
            -v /tmp/.X11-unix:/tmp/.X11-unix \
            -e DISPLAY=unix$DISPLAY \
            -e GDK_SCALE \
            -e GDK_DPI_SCALE \
            --name libreoffice \
            jess/libreoffice

// SublimeText 3
docker run -it \
           -v $HOME/.config/sublime-text-3/:/root/.config/sublime-text-3 \
           -v /tmp/.X11-unix:/tmp/.X11-unix \
           -e DISPLAY=$DISPLAY \
           --name sublime_text \
           jess/sublime-text-3

// Audacity (sound in docker container)
docker run  -d \
            -v /etc/localtime:/etc/localtime:ro \
            -v /tmp/.X11-unix:/tmp/.X11-unix \
            -e DISPLAY=unix$DISPLAY \
            -e QT_DEVICE_PIXEL_RATIO \
            --device /dev/snd \
            --group-add audio \
            --name audacity \
            jess/audacity

// Disable access to x11
xhost -


Docker tips

There are known best practices (see a list at examples/tips)

  • Optimize containers (check fromlatest.io and imagelayers.io)
  • Create your own tiny base
  • Containers are not Virtual Machines
  • Full stack Images VS 1 process per Container
  • Create your private registry
  • Create shortcut commands
  • Use docker-compose.yml templates (see why at lorry.io)
  • Be aware of the hub.docker.com docker agent version

The Docker war

Type Software
Clustering/orchestration Swarm, Kubernetes, Marathon, MaestroNG, decking, shipyard, Apache Mesos
Docker registries Portus, Docker Distribution, hub.docker.com, quay.io, Google container registry, Artifactory, projectatomic.io
PaaS with Docker Rancher, Tsuru, dokku, flynn, Octohost, DEIS
OS made of Containers RancherOS

--

Benchmarking & stats

Docker vs Kubernetes vs Amazon ECS


Docker Alternatives


Instead of Resources

Using Docker


Future events - Docker Cuba

Docker Cuba Join us!
  • Docker Cuba meetups docker.cuban.tech
    • Docker birthday #4 celebration in all provinces

Future events - SciPyLA 2017

SciPyLA 2017 Emerging Computing Technologies

--

Call for papers / reviewers

Call for papers

--

Participate


Questions?

Pythons over Docker!

Review this presentation

Next: Docker in production, Scaling, Private registries, PaaS.

In this presentation I have used oh my zsh, docker 17.03, wharfee and dry.