Book Image

Infrastructure as Code (IAC) Cookbook

By : Stephane Jourdan, Pierre Pomès
Book Image

Infrastructure as Code (IAC) Cookbook

By: Stephane Jourdan, Pierre Pomès

Overview of this book

Para 1: Infrastructure as code is transforming the way we solve infrastructural challenges. This book will show you how to make managing servers in the cloud faster, easier and more effective than ever before. With over 90 practical recipes for success, make the very most out of IAC.
Table of Contents (18 chapters)
Infrastructure as Code (IAC) Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

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"]

Now, each layer is added on top of the previous. So, what's written during the apt-get update layer is written forever, even if we remove it in the last RUN.

Let's rewrite this Dockerfile using a one-liner, to save some space:

FROM ubuntu:16.04
RUN apt...