Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker: multi-stage and multi-environment

Docker: multi-stage and multi-environment

Abdala Cerqueira

May 11, 2019
Tweet

More Decks by Abdala Cerqueira

Other Decks in Programming

Transcript

  1. Dependencies ▷ Easy to add, hard to remove ▷ Security

    problems ▷ Difficult to manage I don’t like dependencies! 5
  2. Install Freedom to install, test and isolate any source code

    in my computer Docker gave me freedom Remove Docker organizes it in a way that is easy to add and delete dependencies safely 6
  3. First part conclusions ▷ No more concerns about dependencies ▷

    Freedom to install and run any source code ▷ It's possible to version almost everything in your machine 8
  4. Dockerfile Problem 1 Keep different Dockerfiles per environment Problem 2

    Send development dependencies to production Problem 3 Create big, huge, immense images. One or two commands may leave images out of control 10
  5. Checklist ▷ Have only one Dockerfile regardless of the environment

    ▷ Don’t have development dependencies in production ▷ Manage less dependencies ▷ Create small images (< 100MB) 15
  6. Examples ▷ Docker in Docker (dind) ▷ Standard Laravel project

    composer create-project laravel/laravel ▷ PHP as Apache module (Horizontal scale) ▷ Pre-downloaded and pre-builded images 16
  7. 17

  8. Checklist ▷ Have only one Dockerfile regardless of the environment

    ▷ Don’t have development dependencies in production ▷ Manage less dependencies ▷ Create small images (< 100MB) 19
  9. “ Multi-stage builds are useful to anyone who has struggled

    to optimize Dockerfiles while keeping them easy to read and maintain. 21 https://docs.docker.com/develop/develop-images/multistage-build
  10. 22

  11. 23

  12. 24

  13. 25

  14. 26

  15. Checklist ▷ Have only one Dockerfile regardless of the environment

    ▷ Don’t have development dependencies in production ▷ Manage less dependencies ▷ Create small images (< 100MB) 27
  16. “ Small. Simple. Secure. Alpine Linux is a security-oriented, lightweight

    Linux distribution based on musl libc and busybox. 29 https://alpinelinux.org
  17. 30

  18. 31

  19. 32

  20. 33

  21. 34

  22. Checklist ▷ Have only one Dockerfile regardless of the environment

    ▷ Don’t have development dependencies in production ▷ Manage less dependencies ▷ Create small images (< 100MB) 35
  23. Comparing images Base image size Image size Compressed image PHP

    378MB 440MB 158.4M PHP Multi-stage 378MB 430MB 153.2M Ubuntu 88.9MB 252MB 86.9M Alpine 5.53MB 43.3MB 12.6M 37
  24. Bonus minidock (minicon, importcon and mergecon) Base image size Image

    size Compressed image Minidock image size Minidock compressed image PHP 378MB 430MB 153.2M 92.5MB 31M Ubuntu 88.9MB 252MB 86.9M 76.7MB 25M Alpine 5.53MB 43.3MB 12.6M - - 38 https://github.com/grycap/minicon
  25. 40

  26. Final considerations ▷ Care about security ▷ Care about dependencies

    ▷ Care about size and speed ▷ Automate your processes 42
  27. Thanks! Any questions? You can find me at: @abdalac Feedback:

    https:/ /joind.in/talk/3e7bc 43 https://joind.in/talk/3e7bc
  28. Credits Special thanks to all the people who made and

    released these awesome resources for free: ▷ Presentation template by SlidesCarnival ▷ Photographs by Unsplash 44