Docker: Layers – Show Image Layers & Size

Docker image is built up from a series of layers that represent instructions in the image’s Dockerfile.

Sometimes it may be necessary to show an image layers, their sizes and the instructions they have been created of.

In this note i will show how to list all layers a Docker image is composed of, show their sizes and the instructions from the image’s Dockerfile.

Cool Tip: Image vs. Container … What is the difference? Read More →

Docker Layers

Show the size of the Docker image:

$ docker images <image>

– example –

$ docker images nginx
REPOSITORY       TAG              IMAGE ID            CREATED             SIZE
nginx            latest           9beeba249f3e        9 days ago          127MB

Show all layers the Docker image is composed of:

$ docker history <image>

– example –

$ docker history nginx:latest
IMAGE         CREATED        CREATED BY                                      SIZE
9beeba249f3e  9 days ago     /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B
<missing>     9 days ago     /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0B
<missing>     9 days ago     /bin/sh -c #(nop)  EXPOSE 80                    0B
<missing>     9 days ago     /bin/sh -c ln -sf /dev/stdout /var/log/nginx…   22B
<missing>     9 days ago     /bin/sh -c set -x     && addgroup --system -…   57.6MB
<missing>     9 days ago     /bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster     0B
<missing>     9 days ago     /bin/sh -c #(nop)  ENV NJS_VERSION=0.3.9        0B
<missing>     9 days ago     /bin/sh -c #(nop)  ENV NGINX_VERSION=1.17.10    0B
<missing>     9 days ago     /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B
<missing>     10 days ago    /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>     10 days ago    /bin/sh -c #(nop) ADD file:7780c81c33e6cc5b6…   69.2MB

Why missing? The <missing> value in the IMAGE field for all but one of the layers of the image, is misleading and a little unfortunate. It conveys the suggestion of an error, but there is no error as layers are no longer synonymous with a corresponding image and ID. Read More →

Don’t truncate output:

$ docker history --no-trunc <image>