Learn about image layers
Make sure Docker is installed on your system and the service is started
# Fedora/RHEL/CentOS
rpm -qa | grep docker
systemctl status docker
FROM ubuntu
EXPOSE 212
ENV foo=bar
WORKDIR /tmp
RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024
RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024
RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024
docker image build -t super_cool_app:latest .
FROM, RUN -> new layer
EXPOSE, ENV, WORKDIR -> metadata
You can run docker image history super_cool_app
. It will show you each instruction and its size. Usually instructions that create new layers has non-zero size, but this is not something you can rely on by itself since, some run commands can have size of zero in docker image history
output (e.g. ls -l
).
You can also use docker image inspect super_cool_appl
and see if in the output, under “RootFS”, there are the number of layers that matches the instructions that should create new layers.
yes, for example, use all the RUN instructions as a single RUN instruction this way:
RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024 && dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024 && dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024
The change in size might not be dramatic in this case, but in some cases it will make a big impact on the image size.