Be a Happier Developer with Docker: Tricks of the Trade
-
Upload
docker-inc -
Category
Documents
-
view
1.050 -
download
0
Transcript of Be a Happier Developer with Docker: Tricks of the Trade
![Page 1: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/1.jpg)
Nicola Paolucci!Developer Advocate / Evangelist
with!
Happier Developerwith
Be a
![Page 2: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/2.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/3.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/4.jpg)
Why?
![Page 5: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/5.jpg)
Compulsion to have clean and perfect
environments
© www.elephantlifestyle.com
![Page 6: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/6.jpg)
the need for speed of every developer with an idea
![Page 7: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/7.jpg)
Fast application mobility, Real repeatability
![Page 8: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/8.jpg)
Great for development team collaboration
![Page 9: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/9.jpg)
Building blocks for your Micro-services Architecture
![Page 10: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/11.jpg)
Workflows & Techniques
![Page 12: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/12.jpg)
Workflow 1: Develop inside a single running container
![Page 13: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/13.jpg)
Workflow 1: Develop inside a single running container
As you would in a single VM
![Page 14: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/14.jpg)
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 15: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/15.jpg)
To use a container as a full Development Environment
phusion/baseimage
![Page 16: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/16.jpg)
Workflow 2: Leverage containers, modularise
![Page 17: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/17.jpg)
Techniques: Embrace Reusability in Dockerfiles
![Page 18: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/18.jpg)
Techniques: Embrace Reusability in Dockerfiles
Write general requirements early, commit and name relevant checkpoints, leave customisations last
![Page 19: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/19.jpg)
add + build routine magicTechniques:
![Page 20: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/20.jpg)
docker add <src> <dest>
![Page 21: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/21.jpg)
docker add <src> <dest>The ADD instruction copies new files from host’s <src> to container’s <dest>
![Page 22: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/22.jpg)
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 23: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/23.jpg)
Sharing data in containersTechniques:
![Page 24: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/24.jpg)
Container
Folder from host:!/app
Docker host
Host folder!/opt/test-app
-v /opt/test-app:/app
host to containersshare folder from
![Page 25: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/25.jpg)
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 26: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/26.jpg)
Same pattern using Dockerfile
FROM busybox VOLUME ["/var/volume1", "/var/volume2"] CMD ["/bin/true"]
![Page 27: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/27.jpg)
Common pattern: Data in containers
Docker host
/var/volume1
DATA
/var/volume2
![Page 28: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/28.jpg)
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 29: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/29.jpg)
Data in containers pattern
Docker host
/var/volume1
DATA
/var/volume2
![Page 30: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/30.jpg)
Data in containers pattern
Docker host
/var/volume1
DATA
/var/volume2
/var/volume1
client1
/var/volume2
--volumes-from DATA--volumes-from DATA
![Page 31: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/31.jpg)
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 32: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/32.jpg)
What if you use docker in a VM?
![Page 33: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/33.jpg)
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 34: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/34.jpg)
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 35: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/35.jpg)
boot2docker is great!
![Page 36: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/36.jpg)
Patched boot2docker with vboxsf support
![Page 37: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/37.jpg)
Patched boot2docker with vboxsf support
Pull Request #282-4 add the feature
![Page 38: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/38.jpg)
Patched boot2docker with vboxsf support
https://vagrantcloud.com/dduportal/boot2docker
![Page 39: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/39.jpg)
The UNIX way: NFS, Samba, plan9, etc.
![Page 40: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/40.jpg)
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 41: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/41.jpg)
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 42: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/42.jpg)
--links: simple service connections for docker
![Page 43: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/43.jpg)
linked containers
Docker host
/var/volume1
postgresql
/var/volume2
client
--link postgresql:pg
can refer to hostname pg in commands
![Page 44: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/44.jpg)
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 45: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/45.jpg)
Tools, Tips & Hacks
![Page 46: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/46.jpg)
workhorse with a secret weapon
![Page 47: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/47.jpg)
Tiny Core Linux
workhorse with a secret weapon
![Page 48: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/48.jpg)
Tiny Core Aside Awesomeness!
Every time it boots, it is brand-spanking new
Minimal nomadic X desktop for 12MB
![Page 49: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/49.jpg)
Customise your boot2docker/Tiny Core
Tailor the boot sequence in!/opt/bootlocal.sh
List personal settings folders and files !/opt/.filetool.lst
![Page 50: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/50.jpg)
Tunnels, tunnels… and ports
![Page 51: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/51.jpg)
Tunnels and ports
Docker in a VMHost OS
8000 8000
Container
8000 8000
-p outer:inner?
![Page 52: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/52.jpg)
Port forwarding into a container
(boot2docker) ssh -L 8000:localhost:8000
Expose a container port to the host machine
![Page 53: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/53.jpg)
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 54: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/54.jpg)
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 55: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/55.jpg)
One more thing…
![Page 56: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/56.jpg)
![Page 57: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/57.jpg)
Nicola Paolucci@durdn
Thank you!
![Page 58: Be a Happier Developer with Docker: Tricks of the Trade](https://reader033.fdocuments.in/reader033/viewer/2022052904/557d90b9d8b42ad6698b4faa/html5/thumbnails/58.jpg)
Nicola Paolucci@durdn
Thank you!