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

Tips for Building Lightweight Docker Images

Tips for Building Lightweight Docker Images

Kelly Andrews

July 21, 2017
Tweet

More Decks by Kelly Andrews

Other Decks in Technology

Transcript

  1. @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
  2. @kellyjandrews Smaller is Better Large Images = Longer Download Times

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

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

    Latest - 786 Wheezy - 719 Slim - 496 Alpine - 329
  5. @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
  6. @kellyjandrews Docker Dieting Tips Use Fewer Layers RUN apt-get update

    -y && \ apt-get install -y curl postgresql postgresql-client
  7. @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/*
  8. @kellyjandrews Docker Dieting Tips Optimize Dockerignore File root # ls

    mycode tmp logs $ echo “tmp” >> .dockerignore $ echo “logs” >> .dockerignore