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
:
1
2
3
4
5
|
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
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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.
Great article. I would also suggest checking out Imagelayers.io from Century Link. It is a graphical representation of the layers and you can actually compare the layers side-by-side. I use this quite often to visualize what’s changed with upgrades.
Brian,
Thanks for sharing the link! Its not able to find jboss/wildfly image. Any idea?
https://gist.github.com/arun-gupta/3b56eb6cbd4790280290
Currently you have JavaScript disabled. In order to post comments, please make sure JavaScript and Cookies are enabled, and reload the page. Click here for instructions on how to enable JavaScript in your browser
docker history --no-trunc --format '{{.CreatedBy}}' IMAGE
I am examining an image (“python:3.5.3-slim”) built by a colleague who has left the company, trying to determine if it originated at dockerhub, and therefore may contain malware. When I run “docker history python:3.5.3-slim”, I get a listing whose bottom line is
10 months ago /bin/sh -c #(nop) ADD file:a023a99f7d01868… 123 MB
Is there any way to determine what this layer is, or where it came from?
In your example, you explain that the bottom line is Ubuntu, and indeed we can see that in the linked Dockerfile, but would there be any way to reconstruct that without having the Dockerfile in hand?
In order to increase your knowledge regarding password manager microsoft edge you may use remember passwords in microsoft edge which will help you to get rid of all your hurdle and will also help you to have exact path for the same.
I wrote a simple tool for Windows to do image tree view and other stuff, maybe someone also finds it useful https://github.com/aloneguid/docker-explorer-windows
In my opinion, advices from https://pro-academic-writers.com/blog/travel-cheap will be useful for students in college. It will help you to travel cheap
Great Article !! Thanks for sharing..