/SlimDockerImages

Tips and tricks for writing nicer and slimmer Docker images

Primary LanguageScala

Slides

Slides, resources and examples for 1st Docker Ljubljana meetup by Oto Brglez, March 2017.

Repository comes with example Scala app and bunch of Dockerfiles where each of the tips is implemented and demonstrated.

Why Scala? Example needed to be complex enough and big enough to matter. If you write apps in C/C++/Go or some other low level compiled language where result is single binary your images would obviously be much smaller.

10 general tips

  1. SRP and KISS - 00
  2. Few layers - 01
  3. Cleanup - 02
  4. copy & extract from host - 03
  5. Less "general" images and lighter base images. 04 + 05
  6. Split 06
  7. .dockerignore
  8. THINK & inspect what you install
  9. test & measure before you optimise
  10. Do not build SW in the container

Example app

Simple Akka HTTP JSON web service that replies with some text and current date/time. Dependencies: Scala, SBT, Java 8.

curl http://localhost:7777/\?name=Oto

Fat-jar size is around 23M.

ls -lh target/**/echo.jar
# ~ 23M

Other

Credits