Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.


Build Docker images with Ansible:
A half-blood approach
William Yeh 

2016-08-27
http://bit.ly/halfblood-docker
Docker is great, but…
Dare you fully migrate your apps to Docker?
Q1
Co-exist?
Q2
The Old Way The Docker Way
Build pipeline
Configuration management
Deployment pipeline
Build pipeline
Configura...
Reuse old, and apply to new…
The Old Way The Docker Way
Build pipeline
Configuration management
Deployment pipeline
Build p...
Should fits into Docker model.
Should be of good quality.
… be a good citizen
in the Docker world
Nginx wrk Boom json-server
built via
package
manager
C compiler Go compiler
Node.js
runtime
http://bit.ly/halfblood-docker
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
1. Use CM to build image.
Base image:

williamyeh/ansible
playbook
1. Use CM to build image.

2. Adapt for Dockerized app.
Major

1. Process execution model.

2. Storage model (embrace immu...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.
Base image: williamyeh/ansible:mini-debia...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
Base image:...
nginx
Background info
• Written in C

• Can be installed via OS-level package manager

(apt, yum, apk, …)
nginx
Debian
Ubuntu
Ce...
1. Use CM to build image.
nginx
playbook
1. Use CM to build image.
nginx
1. Use CM to build image.
nginx
├─<missing> Virtual Size: 125.1 MB
│ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie
│ │
│ └─ad7fe256ceb4 Virtual S...
nginx
1. Use CM to build image.

2. Adapt for Dockerized app.
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.
nginx
williamyeh/ansible:mini-debian8
wil...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.
nginx
├─<missing> Virtual Size: 125.1 MB
...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
nginx
willi...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
nginx
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
nginx
├─<mi...
Should be of good quality.
… be a good citizen in the Docker world
wrk
Background info
• Written in C

• Need to be compiled with gcc (& make).
wrk
https://github.com/wg/wrk
Modern HTTP benchma...
1. Use CM to build image.
wrk
playbook
1. Use CM to build image.
wrk
1. Use CM to build image.
wrk
├─<missing> Virtual Size: 125.1 MB
│ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie
│ │
│ └─ad7fe256ceb4 Virtual S...
wrk
1. Use CM to build image.

2. Adapt for Dockerized app.
N/A
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.
wrk
williamyeh/ansible:mini-debian8
willi...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.
wrk
├─<missing> Virtual Size: 125.1 MB
│ ...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
wrk
william...
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
wrk
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
wrk
├─<miss...
Should be of good quality.
… be a good citizen in the Docker world
Should be of good quality.
… be a good citizen in the Docker world
Boom

json-server
Background info
• Written in Go

• Need to be compiled.

• Written in Node.js

• Need to install Node.js runtime.
Boom
jso...
├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4
│ │
│ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-...
Conclusion
… whether you’d like to dive into Docker

(fully or partially)
“Infrastructure as Code” mindset
… having alternatives is good
Consider Plan B
1. Use CM to build image.

2. Adapt for Dockerized app.

3. Slim down the image.

4. Pursue for minimal image.
Nginx wrk Boom json-server
built via
package
manager
C compiler Go compiler
Node.js
runtime
(near-) minimal
size (MiB)
6.8...
http://bit.ly/halfblood-docker
Upcoming SlideShare
Loading in …5
×

從 Ansible 到 Docker:混血模式 (Build Docker images with Ansible: A half-blood approach)

6,857 views

Published on

Build Docker images with Ansible: A half-blood approach.

聽完課程及演講,常有人問道:「我知道 Docker 很好,但怎樣才能用最簡單的方法,把自家的舊程式升級成 Docker 版?怎樣才能以最少心力在兩者之間交互切換?」

本次講座,我提出自己的獨門祕訣,可同時提供「無 Docker 版」及「Docker 版」兩種軟體 build/ship 模式供你選用;更可在某種範圍內,變成「極簡化的 Docker 程式」,以提供更佳的 Docker 運作品質。



Article (in Chinese): http://school.soft-arch.net/blog/247026/halfblood-docker
Video: https://channel9.msdn.com/Events/Community-Open-Camp/Community-Open-Camp-2016/ComOpenCamp003

Lab materials: https://github.com/William-Yeh/build-docker-with-ansible

Published in: Software

從 Ansible 到 Docker:混血模式 (Build Docker images with Ansible: A half-blood approach)

  1. 1. 
 Build Docker images with Ansible: A half-blood approach William Yeh 
 2016-08-27 http://bit.ly/halfblood-docker
  2. 2. Docker is great, but…
  3. 3. Dare you fully migrate your apps to Docker? Q1
  4. 4. Co-exist? Q2 The Old Way The Docker Way Build pipeline Configuration management Deployment pipeline Build pipeline Configuration management Deployment pipeline inconvenient…
  5. 5. Reuse old, and apply to new… The Old Way The Docker Way Build pipeline Configuration management Deployment pipeline Build pipeline Configuration management Deployment pipeline … with minimal effort … smooth learning curve … ease of maintenance … graceful degradation … be a good citizen My proposal:
  6. 6. Should fits into Docker model. Should be of good quality. … be a good citizen in the Docker world
  7. 7. Nginx wrk Boom json-server built via package manager C compiler Go compiler Node.js runtime http://bit.ly/halfblood-docker
  8. 8. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image.
  9. 9. 1. Use CM to build image. Base image:
 williamyeh/ansible playbook
  10. 10. 1. Use CM to build image. 2. Adapt for Dockerized app. Major 1. Process execution model. 2. Storage model (embrace immutable infra, please). 3. Network model. Ref. "Dockerized app " 
 http://william-yeh.github.io/docker-workshop/slides/dockerize.html Minor 4. Log handling. 5. Init/upstart/systemd handling. 6. Wrapper scripts as new entrypoint, if necessary.
  11. 11. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. Base image: williamyeh/ansible:mini-debian8 Minimal configuration: the Ansible body will be removed when mission completed.
  12. 12. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. Base image: williamyeh/ansible:mini-alpine3 Ref: 1. " Docker image " http://william-yeh.github.io/docker-mini/ 2. " Alpine Linux"
 http://school.soft-arch.net/courses/docker-part2/lectures/885446 use Alpine Linux in Ansible playbooks. playbook
  13. 13. nginx
  14. 14. Background info • Written in C • Can be installed via OS-level package manager
 (apt, yum, apk, …) nginx Debian Ubuntu CentOS RHEL Fedora Alpine
  15. 15. 1. Use CM to build image. nginx playbook
  16. 16. 1. Use CM to build image. nginx
  17. 17. 1. Use CM to build image. nginx
  18. 18. ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ │ │ └─482d24d32738 Virtual Size: 210.5 MB │ │ │ └─5b8665aa9bbc Virtual Size: 241.2 MB Tags: nginx-1:latest 1. Use CM to build image. nginx
  19. 19. nginx 1. Use CM to build image. 2. Adapt for Dockerized app.
  20. 20. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. nginx williamyeh/ansible:mini-debian8 williamyeh/ansible:debian8-onbuild Base image:
  21. 21. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. nginx ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─68b7807607da Virtual Size: 135.9 MB Tags: nginx-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─5b8665aa9bbc Virtual Size: 241.2 MB Tags: nginx-1:latest
  22. 22. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. nginx williamyeh/ansible:mini-alpine3 williamyeh/ansible:mini-debian8 Base image:
  23. 23. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. nginx
  24. 24. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. nginx ├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4 │ │ │ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-alpine3 │ └─b57f615a2cd9 Virtual Size: 6.8 MB Tags: nginx-4:latest │ ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─68b7807607da Virtual Size: 135.9 MB Tags: nginx-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─5b8665aa9bbc Virtual Size: 241.2 MB Tags: nginx-1:latest
  25. 25. Should be of good quality. … be a good citizen in the Docker world
  26. 26. wrk
  27. 27. Background info • Written in C • Need to be compiled with gcc (& make). wrk https://github.com/wg/wrk Modern HTTP benchmarking tool
  28. 28. 1. Use CM to build image. wrk playbook
  29. 29. 1. Use CM to build image. wrk
  30. 30. 1. Use CM to build image. wrk
  31. 31. ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ │ │ └─482d24d32738 Virtual Size: 210.5 MB │ └─e755d268bd41 Virtual Size: 341.0 MB Tags: wrk-1:latest 1. Use CM to build image. wrk
  32. 32. wrk 1. Use CM to build image. 2. Adapt for Dockerized app. N/A
  33. 33. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. wrk williamyeh/ansible:mini-debian8 williamyeh/ansible:debian8-onbuild Base image:
  34. 34. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. wrk ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─980aa6023fda Virtual Size: 164.3 MB Tags: wrk-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─e755d268bd41 Virtual Size: 341.0 MB Tags: wrk-1:latest
  35. 35. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. wrk williamyeh/ansible:mini-alpine3 williamyeh/ansible:mini-debian8 Base image:
  36. 36. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. wrk
  37. 37. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image. wrk ├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4 │ │ │ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-alpine3 │ └─531aed862a98 Virtual Size: 9.1 MB Tags: wrk-4:latest │ ├─<missing> Virtual Size: 125.1 MB │ └─<missing> Virtual Size: 125.1 MB Tags: debian:jessie │ │ │ ├─cb9b094476db Virtual Size: 125.1 MB Tags: williamyeh/ansible:mini-debian8 │ │ └─980aa6023fda Virtual Size: 164.3 MB Tags: wrk-3:latest │ │ │ └─ad7fe256ceb4 Virtual Size: 200.9 MB Tags: williamyeh/ansible:debian8-onbuild │ └─482d24d32738 Virtual Size: 210.5 MB │ └─e755d268bd41 Virtual Size: 341.0 MB Tags: wrk-1:latest
  38. 38. Should be of good quality. … be a good citizen in the Docker world
  39. 39. Should be of good quality. … be a good citizen in the Docker world
  40. 40. Boom json-server
  41. 41. Background info • Written in Go • Need to be compiled. • Written in Node.js • Need to install Node.js runtime. Boom json-server
  42. 42. ├─<missing> Virtual Size: 4.8 MB Tags: alpine:3.4 │ │ │ └─c887641f2cdb Virtual Size: 4.8 MB Tags: williamyeh/ansible:mini-alpine3 │ │ │ ├─fc72e24cae3c Virtual Size: 14.5 MB Tags: williamyeh/boom:latest │ │
 │ └─bfd0226b6d74 Virtual Size: 27.5 MB Tags: williamyeh/json-server:latest https://github.com/William-Yeh/docker-boom https://github.com/William-Yeh/docker-json-server
  43. 43. Conclusion
  44. 44. … whether you’d like to dive into Docker
 (fully or partially) “Infrastructure as Code” mindset
  45. 45. … having alternatives is good Consider Plan B
  46. 46. 1. Use CM to build image. 2. Adapt for Dockerized app. 3. Slim down the image. 4. Pursue for minimal image.
  47. 47. Nginx wrk Boom json-server built via package manager C compiler Go compiler Node.js runtime (near-) minimal size (MiB) 6.8 9.1 14.51 27.48
  48. 48. http://bit.ly/halfblood-docker

×