Show Layers of Docker Image
Every speaking opportunity is a learning lesson, and hence a new opportunity to share. This blog will address one of the questions that has been bothering me for the past few days. It is about how to show different layers of Docker image, and their sizes, after it is downloaded.
I was invited to talk about Docker for Java developers at Peru JUG this morning. The recording is now available:
The real content starts from 5:27.
Lets address the question now.
Each Docker image consists of a series of layers. Here is a quote from docs.docker.com:
Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image. Union file systems allow files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.
The exact size of the image can be easily seen using docker images
:
docker images couchbase REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE couchbase latest 45abdd57689a 3 weeks ago 372 MB
The command to show different layers, and their size, is docker history
:
docker history couchbase IMAGE CREATED CREATED BY SIZE COMMENT 45abdd57689a 3 weeks ago /bin/sh -c #(nop) VOLUME [/opt/couchbase/var] 0 B dd8c5611343d 3 weeks ago /bin/sh -c #(nop) EXPOSE 11207/tcp 11210/tcp 0 B 30852bbad62b 3 weeks ago /bin/sh -c #(nop) CMD ["couchbase-server"] 0 B 5537747ea12f 3 weeks ago /bin/sh -c #(nop) ENTRYPOINT &{["/entrypoint. 0 B e8a83a5448df 3 weeks ago /bin/sh -c #(nop) COPY file:cbb44c9c65b64a9dc 182 B 18165b90fefa 3 weeks ago /bin/sh -c #(nop) COPY file:34e32c52f0895191f 389 B 5f37b8bdc5a6 3 weeks ago /bin/sh -c wget -N $CB_RELEASE_URL/$CB_VERSIO 212.1 MB 1a8da511d01b 3 weeks ago /bin/sh -c groupadd -g 1000 couchbase && user 328.7 kB d9b2222c39b4 3 weeks ago /bin/sh -c #(nop) ENV CB_VERSION=4.0.0 CB_REL 0 B 815f08b3c781 3 weeks ago /bin/sh -c apt-get update && apt-get inst 23.57 MB fc38f156c0ea 3 weeks ago /bin/sh -c #(nop) MAINTAINER Couchbase Docker 0 B 2a7a952931ec 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B 10f1b5844a9c 3 weeks ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.911 kB 23c388b926b6 3 weeks ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 156.2 kB b45376f323f5 3 weeks ago /bin/sh -c #(nop) ADD file:4a9e089e81d6581a54 135.9 MB
This command shows different layers, command used for each layer, and the exact size of each image.
The corresponding Dockerfile for this image is at github.com/couchbase/docker/blob/master/enterprise/couchbase-server/4.0.0/Dockerfile.
Now I can compare the Dockerfile with the exact size and easily find which image layers are the biggest. For example, biggest contributors in this Couchbase image are shown below:
- Ubuntu from Dockerfile 12.04 is 135.9 MB
- apt-get from Dockerfile causes another 23.57 MB
- Couchbase server is 212 MB
--no-trunc
can be specified as an additional CLI option to history
to show the complete command executed to build the layer.
- As always, the latest slides are available at github.com/javaee-samples/docker-java/tree/master/slides.
Reference: | Show Layers of Docker Image from our JCG partner Arun Gupta at the Miles to go 2.0 … blog. |