Transcript
Page 1: Be a happier developer with Docker: Tricks of the trade

Nicola Paolucci!Developer Advocate / Evangelist

with!

Happier Developerwith

Be a

Page 2: Be a happier developer with Docker: Tricks of the trade

Nicola Paolucci@durdn

Bio pictures: the subtle pleasure of embarrassing yourself in front of hundreds of people

Page 3: Be a happier developer with Docker: Tricks of the trade

Tools, Tips and Hacks

2

3

The plan for this session:

Notes on Workflows and Techniques

1 Why does Docker make Developers happy?

Page 4: Be a happier developer with Docker: Tricks of the trade

Why?

Page 5: Be a happier developer with Docker: Tricks of the trade

Compulsion to have clean and perfect

environments

© www.elephantlifestyle.com

Page 6: Be a happier developer with Docker: Tricks of the trade

the need for speed of every developer with an idea

Page 7: Be a happier developer with Docker: Tricks of the trade

Fast application mobility, Real repeatability

Page 8: Be a happier developer with Docker: Tricks of the trade

Great for development team collaboration

Page 9: Be a happier developer with Docker: Tricks of the trade

Building blocks for your Micro-services Architecture

Page 10: Be a happier developer with Docker: Tricks of the trade

Micro-services Architecture Blueprint

@crichardson

!!!!!

Traditional Server-side web apps

View Controller

Model

API Gateway

!!!!!

Browser/Native App

View Controller

Model

REST

REST

REST

Product Info Service

Recommendation Service

Review Service

Single entry point

Protocol translationClient specific APIs

Page 11: Be a happier developer with Docker: Tricks of the trade

Workflows & Techniques

Page 12: Be a happier developer with Docker: Tricks of the trade

Workflow 1: Develop inside a single running container

As you would in a single VM

Page 13: Be a happier developer with Docker: Tricks of the trade

Container

Start a shell in container docker run -i -t ubuntu /bin/bash

Folder from host:!/src

Docker host

Host folder!/path/to/code

-v /path/to/code:/src

Page 14: Be a happier developer with Docker: Tricks of the trade

To use a container as a full Development Environment

phusion/baseimage

Page 15: Be a happier developer with Docker: Tricks of the trade

Workflow 2: Leverage containers, modularise

Page 16: Be a happier developer with Docker: Tricks of the trade

Techniques: Embrace Reusability in Dockerfiles

Write general requirements early, commit and name relevant checkpoints, leave customisations last

Page 17: Be a happier developer with Docker: Tricks of the trade

add + build routine magicTechniques:

Page 18: Be a happier developer with Docker: Tricks of the trade

docker add <src> <dest>

Page 19: Be a happier developer with Docker: Tricks of the trade

docker add <src> <dest>The ADD instruction copies new files from host’s <src> to container’s <dest>

Page 20: Be a happier developer with Docker: Tricks of the trade

docker build your image with updated code

1

2

add + build routine magic?!

Update code in local app folder (git pull?)

Distribute and profit!3

Page 21: Be a happier developer with Docker: Tricks of the trade

Sharing data in containersTechniques:

Page 22: Be a happier developer with Docker: Tricks of the trade

Container

Folder from host:!/app

Docker host

Host folder!/opt/test-app

-v /opt/test-app:/app

host to containersshare folder from

Page 23: Be a happier developer with Docker: Tricks of the trade

host to containers

docker run -v /opt/test-app:/app \ -i -t ubuntu /bin/bash

Use the run -v (volume option) to specify host/container folder to be synced

From

is simple

Page 24: Be a happier developer with Docker: Tricks of the trade

Same pattern using Dockerfile

FROM busybox VOLUME ["/var/volume1", "/var/volume2"] CMD ["/bin/true"]

Page 25: Be a happier developer with Docker: Tricks of the trade

Common pattern: Data in containers

Docker host

/var/volume1

DATA

/var/volume2

Page 26: Be a happier developer with Docker: Tricks of the trade

Common pattern: data in containers

docker run -v /var/volume1 \ -v /var/volume2 \ --name DATA busybox true

Switched off, named, data container which exposes a folder

Page 27: Be a happier developer with Docker: Tricks of the trade

Data in containers pattern

Docker host

/var/volume1

DATA

/var/volume2

Page 28: Be a happier developer with Docker: Tricks of the trade

Data in containers pattern

Docker host

/var/volume1

DATA

/var/volume2

/var/volume1

client1

/var/volume2

--volumes-from DATA--volumes-from DATA

Page 29: Be a happier developer with Docker: Tricks of the trade

Common pattern: data in containers

docker run -t -i -rm --volumes-from DATA \ --name client1 ubuntu bash

Then mount the data container in your application containers

Page 30: Be a happier developer with Docker: Tricks of the trade

What if you use docker in a VM?

Page 31: Be a happier developer with Docker: Tricks of the trade

Container

You have an extra layer

Container folder!/src

Docker in a VM

VM folder!/path/to/code

-v /path/to/code:/src

Host OS

Host OS folder!/path/to/code

?

Page 32: Be a happier developer with Docker: Tricks of the trade

Simplest way: Use Guest Additions

And a VM that supports shared folders. But what if you want to keep using the

lightest weight genius of boot2docker?

Page 33: Be a happier developer with Docker: Tricks of the trade

boot2docker is great!

Page 34: Be a happier developer with Docker: Tricks of the trade

Patched boot2docker with vboxsf support

Page 35: Be a happier developer with Docker: Tricks of the trade

Patched boot2docker with vboxsf support

Pull Request #282-4 add the feature

Page 36: Be a happier developer with Docker: Tricks of the trade

Patched boot2docker with vboxsf support

https://vagrantcloud.com/dduportal/boot2docker

Page 37: Be a happier developer with Docker: Tricks of the trade

The UNIX way: NFS, Samba, plan9, etc.

Page 38: Be a happier developer with Docker: Tricks of the trade

Access via NFS

docker pull cpuguy83/nfs-server

Pull the right image, share a data folder in it, share it with other containers AND the host

docker run -d --name nfs --privileged \ cpuguy83/nfs-server /path/to/share

Page 39: Be a happier developer with Docker: Tricks of the trade

Access via Samba

docker pull svendowideit/samba

And if you prefer Samba, here’s a shortcut ready made for you

docker run svendowideit/samba data

Page 40: Be a happier developer with Docker: Tricks of the trade

--links: simple service connections for docker

Page 41: Be a happier developer with Docker: Tricks of the trade

linked containers

Docker host

/var/volume1

postgresql

/var/volume2

client

--link postgresql:pg

can refer to hostname pg in commands

Page 42: Be a happier developer with Docker: Tricks of the trade

Sample access to linked container

docker build -t postresql .

Build the image, run it with a name, !link in child container

docker run -rm -P --name pg postgresql

docker run -rm -t -i --link pg:pg postgresql bash !psql -h pg -d docker -U docker --password

Page 43: Be a happier developer with Docker: Tricks of the trade

Tools, Tips & Hacks

Page 44: Be a happier developer with Docker: Tricks of the trade

workhorse with a secret weapon

Page 45: Be a happier developer with Docker: Tricks of the trade

Tiny Core Linux

workhorse with a secret weapon

Page 46: Be a happier developer with Docker: Tricks of the trade

Tiny Core Aside Awesomeness!

Every time it boots, it is brand-spanking new

Minimal nomadic X desktop for 12MB

Page 47: Be a happier developer with Docker: Tricks of the trade

Customise your boot2docker/Tiny Core

Tailor the boot sequence in!/opt/bootlocal.sh

List personal settings folders and files !/opt/.filetool.lst

Page 48: Be a happier developer with Docker: Tricks of the trade

Tunnels, tunnels… and ports

Page 49: Be a happier developer with Docker: Tricks of the trade

Tunnels and ports

Docker in a VMHost OS

8000 8000

Container

8000 8000

-p outer:inner?

Page 50: Be a happier developer with Docker: Tricks of the trade

Port forwarding into a container

(boot2docker) ssh -L 8000:localhost:8000

Expose a container port to the host machine

Page 51: Be a happier developer with Docker: Tricks of the trade

Mass-expose ports with VBoxManage

# vm must be powered off for i in {49000..49900}; do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i"; VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i"; done

To expose all 49XXX ports you can run:

Workarounds section of boot2docker docs

Page 52: Be a happier developer with Docker: Tricks of the trade

Open ports on live containers with force using iptables

sudo iptables-save

http://j.mp/force-port

Note down the command to open ports of another container

Page 53: Be a happier developer with Docker: Tricks of the trade

One more thing…

Page 54: Be a happier developer with Docker: Tricks of the trade
Page 55: Be a happier developer with Docker: Tricks of the trade

Nicola Paolucci@durdn

Thank you!


Top Related