docker extended

 

docker

 

client

daemon

http :2376

https://github.com/stage1/docker-php

$ docker -H tcp://192.168.10.1:2376 ps

$ export DOCKER_HOST="tcp://192.168.10.1:2376"
$ docker ps

client

local daemon

virtual machine

remote server

docker-machine

 

docker-machine

  • ls
  • create
  • start
  • stop
  • status
  • ssh
  • upgrade
  • rm
  • ...
$ docker-machine create --driver virtualbox demo
...


$ docker-machine ls
NAME           ACTIVE   DRIVER       STATE     URL                         SWARM
demo           -        virtualbox   Running   tcp://192.168.99.100:2376   


$ docker-machine env demo
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/jderusse/.docker/machine/machines/demo"
export DOCKER_MACHINE_NAME="demo"
# Run this command to configure your shell: 
# eval "$(/usr/local/bin/docker-machine env demo)"


$ eval "$(docker-machine env demo)"


$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

https://github.com/docker/machine/blob/master/contrib/completion/bash/docker-machine.bash

available drivers

  • Oracle VirtualBox
  • VMware vSphere
  • Amazon Web Services
  • Microsoft Azure
  • Digital Ocean
  • Google Compute Engine
  • OpenStack
  • ...
  • Generic

https://docs.docker.com/machine/drivers/

$ docker-machine create --driver amazonec2 \
    --amazonec2-access-key AKI******* \
    --amazonec2-secret-key 8T93C********* \
    --amazonec2-vpc-id vpc-****** \
    --amazonec2-ami ami-5f709f34 \
    --amazonec2-root-size 16 \
    demo2
$ tree ~/.docker/
/home/jderusse/.docker/
└── machine
    ├── certs
    │   ├── ca-key.pem
    │   ├── ca.pem
    │   ├── cert.pem
    │   └── key.pem
    └── machines
        ├── demo
        │   ├── boot2docker.iso
        │   ├── ca.pem
        │   ├── cert.pem
        │   ├── config.json
        │   ├── demo
        │   │   ├── demo.vbox
        │   │   ├── demo.vbox-prev
        │   │   └── Logs
        │   │       └── VBox.log
        │   ├── disk.vmdk
        │   ├── id_rsa
        │   ├── id_rsa.pub
        │   ├── key.pem
        │   ├── server-key.pem
        │   └── server.pem
        └── demo2
            ├── ca.pem
            ├── cert.pem
            ├── config.json
            ├── id_rsa
            ├── id_rsa.pub
            ├── key.pem
            ├── server-key.pem
            └── server.pem

docker volume

 

docker volume

  • ls
  • create
  • inspect
  • rm
$ docker volume create --name demo_volume
demo_volume

$ docker run -v demo_volume:/foo debian touch /foo/test

$ docker run -v demo_volume:/bar debian ls -al /bar
total 8
drwxr-xr-x 2 root root 4096 Jan  5 12:12 .
drwxr-xr-x 1 root root 4096 Jan  5 12:12 ..
-rw-r--r-- 1 root root    0 Jan  5 12:12 test

plugins

  • flocker
  • nfs
  • convoy
  • glusterfs
  • rex-ray
  • ...
$ docker volume create --driver nfs --name localhost/demo 

$ docker run --rm -v localhost/demo:/foo debian ls -al /foo

docker network

 

docker network

  • ls
  • create
  • connect
  • disconnect
  • inspect
  • rm
$ docker network create demo

$ docker network ls
NETWORK ID          NAME                DRIVER
b7c9b6d0c133        demo                bridge  
bfc56a57191f        none                null                
0a07e021ffd5        host                host                
a69e42ce961a        bridge              bridge              

$ docker run --rm -ti \
  --name hostA \
  debian bash
$ docker run --rm -ti \
  --name hostB \
  --net demo \
  debian bash
$ docker run --rm -ti \
  --name hostC \
  --net demo \
  debian bash
$ ping -c 1 hostB
ping: unknown host
$ ping -c 1 hostC                                                                                   
PING hostC (172.21.0.4): 56 data bytes
64 bytes from 172.21.0.4: icmp_seq=0 ttl=64 time=0.069 ms
--- hostC ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.069/0.069/0.069/0.000 ms
$ ping -c 1 hostA                                                                               
ping: unknown host
$ docker network connect demo hostA
$ ping -c 1 hostB                                                                                   
PING hostB (172.21.0.3): 56 data bytes
64 bytes from 172.21.0.3: icmp_seq=0 ttl=64 time=0.069 ms
--- hostB ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.069/0.069/0.069/0.000 ms
$ ping -c 1 hostC                                                                                   
PING hostC (172.21.0.4): 56 data bytes
64 bytes from 172.21.0.4: icmp_seq=0 ttl=64 time=0.069 ms
--- hostC ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.069/0.069/0.069/0.000 ms
$ ping -c 1 hostA
PING hostA (172.21.0.2): 56 data bytes
64 bytes from 172.21.0.2: icmp_seq=0 ttl=64 time=0.069 ms
--- hostA ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.069/0.069/0.069/0.000 ms
$ docker run --rm -ti \
  --name hostA \
  debian bash
$ docker run --rm -ti \
  --name hostB \
  --net demo \
  debian bash
$ docker run --rm -ti \
  --name hostC \
  --net demo \
  debian bash
app:
    build: docker/app
    volumes:
        - .:/srv
    links:
        - db

db:
    image: postgres

BEFORE

app:
    build: docker/app
    volumes:
        - .:/srv
    net: app

db:
    image: postgres
    net: app

AFTER

app:
    build: docker/app
    volumes:
        - .:/srv

db:
    image: postgres

OR

$ docker-compose --x-networking up
$ docker network create front

$ docker network create back


$ docker network connect front app

$ docker network connect front rabbitmq
$ docker network connect back rabbitmq

$ docker network connect back worker

front

back

app

rabbitmq

worker

plugins

  • bridge
  • overlay
  • weave
  • ...
$ docker network create --driver overlay front

$ docker-compose up -d app

$ docker-compose scale app=3

docker swarm

 

docker run --rm swarm

 

$ docker run swarm create
cdd37d9dd457616dfd0c1255fa43cc5f

$ docker-machine create \
        -d virtualbox \
        --swarm \
        --swarm-master \
        --swarm-discovery token://cdd37d9dd457616dfd0c1255fa43cc5f \
        swarm-master

$ docker-machine create \
        -d virtualbox \
        --swarm \
        --swarm-discovery token://cdd37d9dd457616dfd0c1255fa43cc5f \
        swarm-node-01

$ docker-machine ls
NAME            ACTIVE   DRIVER       STATE     URL                         SWARM
demo            -        virtualbox   Running   tcp://192.168.99.100:2376   
swarm-master    *        virtualbox   Running                               swarm-master (master)
swarm-node-01   *        virtualbox   Running                               swarm-master

$ docker-machine env --swarm swarm-master
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:3376"
export DOCKER_CERT_PATH="/home/jderusse/.docker/machine/machines/swarm-master"
export DOCKER_MACHINE_NAME="swarm-master"
$ eval "$(docker-machine env --swarm swarm-master)"

$ docker run -d nginx

$ docker ps
CONTAINER ID  IMAGE  COMMAND                 PORTS            NAMES
d1ef73f4d236  nginx  "nginx -g 'daemon off"  80/tcp, 443/tcp  swarm-node-01/distracted_mccarthy

$ docker run -d nginx

$ docker ps
CONTAINER ID  IMAGE  COMMAND                 PORTS            NAMES
d1ef73f4d236  nginx  "nginx -g 'daemon off"  80/tcp, 443/tcp  swarm-node-01/distracted_mccarthy
4c13d63943b6  nginx  "nginx -g 'daemon off"  80/tcp, 443/tcp  swarm-master/desperate_engelbart
$ eval "$(docker-machine env swarm-master)"

$ docker ps
CONTAINER ID  IMAGE         COMMAND                 PORTS              NAMES
d1ef73f4d236  nginx         "nginx -g 'daemon off"  80/tcp, 443/tcp    distracted_mccarthy
d4b622c7bca7  swarm:latest  "/swarm join --advert"  2375/tcp           swarm-agent
$ eval "$(docker-machine env swarm-master)"

$ docker ps
CONTAINER ID  IMAGE         COMMAND                 PORTS              NAMES
4c13d63943b6  nginx         "nginx -g 'daemon off"  80/tcp, 443/tcp    desperate_engelbart
837fc704ec30  swarm:latest  "/swarm join --advert"  2375/tcp           swarm-agent
d3a6552596e7  swarm:latest  "/swarm manage --tlsv"  2375/tcp, 0.0.0.0  swarm-agent-master
$ docker run swarm create
cdd37d9dd457616dfd0c1255fa43cc5f

$ docker-machine create \
        -d virtualbox \
        --swarm \
        --swarm-master \
        --swarm-discovery token://cdd37d9dd457616dfd0c1255fa43cc5f \
        swarm-master



$ docker-machine create \
        -d virtualbox \
        --swarm \
        --swarm-discovery token://cdd37d9dd457616dfd0c1255fa43cc5f \
        swarm-node-01



$ docker-machine create \
        -d virtualbox \
        --swarm \
        --swarm-master \
        --swarm-discovery="consul://my_consul_host:8500" \
        --engine-opt="cluster-store=consul://my_consul_host:8500" \
        --engine-opt="cluster-advertise=eth1:2376" \
        swarm-master

$ docker-machine create \
        -d virtualbox \
        --swarm \
        --swarm-discovery="consul://my_consul_host:8500" \
        --engine-opt="cluster-store=consul://my_consul_host:8500" \
        --engine-opt="cluster-advertise=eth1:2376" \
        swarm-node-01

$ docker network create --driver overlay demo

swarm-master

swarm-node-01

demo

 

 

 

 

side effects

  • not stable (consul unreachable)
  • no links => docker network
  • no volumes_from => docker volume ?
  • no shares with host => everything in containers

Questions ?

Made with Slides.com