O'Reilly logo

Infrastructure as Code (IAC) Cookbook by Pierre Pomes, Stephane Jourdan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Optimizing the Docker image size

Docker images are generated instruction by instruction from the Dockerfile. Though perfectly correct, many images are sub-optimized when we're talking about size. Let's see what we can do about it by building an Apache Docker container on Ubuntu 16.04.

Getting ready

To step through this recipe, you will need a working Docker installation.

How to do it…

Take the following Dockerfile, which updates the Ubuntu image, installs the apache2 package, and then removes the /var/lib/apt cache folder. It's perfectly correct, and if you build it, the image size is around 260 MB:

FROM ubuntu:16.04 RUN apt-get update -y RUN apt-get install -y apache2 RUN rm -rf /var/lib/apt ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required