VOOZH about

URL: https://www.javacodegeeks.com/2015/12/show-layers-docker-image.html

⇱ Show Layers of Docker Image - Java Code Geeks


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.

How does a Docker image work?

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:

--no-trunc can be specified as an additional CLI option to history to show the complete command executed to build the layer.

Reference: Show Layers of Docker Image from our JCG partner Arun Gupta at the Miles to go 2.0 … blog.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
Docker
👁 Photo of Arun Gupta
Arun Gupta
December 15th, 2015Last Updated: December 14th, 2015
0 133 2 minutes read

Arun Gupta

Arun is a technology enthusiast, avid runner, author of a best-selling book, globe trotter, a community guy, Java Champion, JavaOne Rockstar, JUG Leader, Minecraft Modder, Devoxx4Kids-er, and a Red Hatter.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz