![docker inspect layer size docker inspect layer size](https://data-flair.training/blogs/wp-content/uploads/sites/2/2018/10/Docker-Images-01-1024x537.jpg)
- Docker inspect layer size how to#
- Docker inspect layer size install#
- Docker inspect layer size plus#
Let’s see the final image size: $ docker build -t tip2. You can see here that the curl package is immediately removed after being installed, in a separate instruction.
Docker inspect layer size install#
RUN apt-get update & apt-get install -y curl & curl RUN apt-get remove -y curl Let’s see another interesting example in which we remove a temporary package in a separate instruction: FROM ubuntu:16.04 Tip1 latest 2886d17dc7f4 9 seconds ago 248 MBĪlthough the size difference is not so significant, you can expect better results when installing multiple packages. Let’s build our image again: $ docker build -t tip1.
![docker inspect layer size docker inspect layer size](https://i.stack.imgur.com/J2cge.jpg)
RUN apt-get update & apt-get install -y curl mysql-client Now, let’s gather the two instructions in only one: FROM ubuntu:16.04 To illustrate this statement, let’s build an image with two separate RUN instructions which install curl and mysql-client packages: FROM ubuntu:16.04 Let's compare multiple and single instructions by installing/removing packages : Installing packages Separate instructions
![docker inspect layer size docker inspect layer size](https://image.slidesharecdn.com/dockerimage-150828004109-lva1-app6891/85/optimizing-docker-images-8-320.jpg)
Group commands in ONE instruction when possibleĭo not perform multiple installs in multiple RUN instructions. To reduce the final size, we have to focus on the intermediate layers.Īlthough some of them cannot be reduced (especially the one you start from), we can use a few tips to help reduce the final image size.
Docker inspect layer size how to#
How to reduce image sizeĪs we just saw, the layers play an important role in the final image size. If the intermediate layer is not found or has changed, the Docker daemon will pull or rebuild it. When building an image, the Docker daemon will check if the intermediate image (layer created by the instruction) already exists in its cache to reuse it.
Docker inspect layer size plus#
The final image built from this Dockerfile contains 3 layers plus all Ubuntu image layers.Īlthough this can be somehow difficult to understand, this structure is very important as it allows Docker to cache layers to make the builds much faster. You can see below that each layer have a size and a command associated to create it. To see the intermediate layers of an image, type the following command: $ docker history curlħ32afd2af5a9 About an hour ago /bin/sh -c apt-get install -y curl 11.32 MBĩ12b76f3dd8e About an hour ago /bin/sh -c mkdir -p /some/dir 0 Bĥ25804109d88 About an hour ago /bin/sh -c #(nop) MAINTAINER Florian Lopes 0 BĬ88b54fedc4f 9 days ago /bin/sh -c #(nop) CMD 0 BĤ4802199e669 9 days ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kBħ4a2c71e6050 9 days ago /bin/sh -c set -xe & echo '#!/bin/sh' > /u 194.5 kBġ40d9fb3c81c 9 days ago /bin/sh -c #(nop) ADD file:ed7184ebed5263e677 187.8 MB Test latest 732afd2af5a9 About an hour ago 199.3 MB REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE Let’s build this image: $ docker build -t curl.
![docker inspect layer size docker inspect layer size](https://developers.redhat.com/sites/default/files/styles/share/public/blog/2015/01/docker-whale-home-logo.png)
This layers stack allows Docker to reuse images when a similar instruction is found.Įach Dockerfile instruction creates a layer at build time: FROM ubuntu # This base image is already composed of X layers (4 at the time of writing) To reduce an image size, it’s important to understand what a layer is.Įvery Docker image is composed of multiple intermediate images (layers) which form the final image. Better security due to smaller footprint.Reducing Docker final image size will eventually lead to: Update: Docker 1.13 introduced a new –squash option to squash the image layers (experimental): -squash-experimental-only (thanks Why is the image size so important? This post will give you 5 tips to help reduce your Docker images size and why focusing on it is important. Although the gigabyte price is decreasing, keeping your Docker images light will bring some benefits. Docker images can quickly weight 1 or more GB.