Save 37% off PRO during our Black Friday Sale! »

Tips for Building Lightweight Docker Images

Tips for Building Lightweight Docker Images

66426218db33a09009947d5b56b947c8?s=128

Kelly Andrews

July 21, 2017
Tweet

Transcript

  1. @kellyjandrews Tips for Building Lightweight Docker Images Kelly J Andrews

    - Developer Advocate, Codeship
  2. @kellyjandrews Docker Images

  3. @kellyjandrews Docker Images

  4. @kellyjandrews Docker Images What is a docker image

  5. @kellyjandrews Docker Images A Docker image is built up from

    a series of layers. Each layer represents an instruction in the image’s Dockerfile. Each layer except the very last one is read-only. Source: docker.com
  6. @kellyjandrews Docker Images FROM ubuntu:15.04 COPY . /app RUN make

    /app CMD python /app/app.py
  7. @kellyjandrews Docker Images Source: docker.com

  8. @kellyjandrews Docker Images Source: docker.com

  9. @kellyjandrews Smaller = Better

  10. @kellyjandrews Smaller is Better Large Images = Longer Download Times

    Node Latest - 84 sec. Wheezy - 63 sec. Slim - 13 sec. Alpine - 12 sec.
  11. @kellyjandrews Smaller is Better Large Images = More Disk Space

    Node Latest 667 MB Wheezy 522 MB Slim 226 MB Alpine 64.7 MB
  12. @kellyjandrews Smaller is Better Large Images = Unused Programs Node

    Latest - 786 Wheezy - 719 Slim - 496 Alpine - 329
  13. @kellyjandrews Docker Dieting Tips

  14. @kellyjandrews Docker Dieting Tips Best Practices for Building Minimal Docker

    Images https://resources.codeship.com/ebooks
  15. @kellyjandrews Docker Dieting Tips Use Fewer Layers RUN apt-get update

    -y RUN apt-get install -y curl RUN apt-get install -y postgresql RUN apt-get install -y postgresql-client
  16. @kellyjandrews Docker Dieting Tips Use Fewer Layers RUN apt-get update

    -y && \ apt-get install -y curl postgresql postgresql-client
  17. @kellyjandrews Docker Dieting Tips Clean Up After Yourself RUN apt-get

    update -y && \ apt-get install -y curl postgresql postgresql-client && \ rm -rf /var/lib/apt/lists/*
  18. @kellyjandrews Docker Dieting Tips Base Images Node Latest 667 MB

    Wheezy 522 MB Slim 226 MB Alpine 64.7 MB
  19. @kellyjandrews Docker Dieting Tips Optimize Dockerignore File root # ls

    mycode tmp logs $ echo “tmp” >> .dockerignore $ echo “logs” >> .dockerignore
  20. @kellyjandrews Docker Dieting Tips Jessie Frazelle github.com/jessfraz/dockerfiles