Earlier this week, I was writing a Dockerfile to download and run a binary when I noticed the image size was way more
than what I would expect. I’m using ubuntu:21.10 as the base image, which is about 70MB. The binary I’m running
is about 80MB. Other packages I’m installing would add 10-ish MB. But the image size is 267MB?
Clearly I’m doing something wrong. But what? My Dockerfile is fairly simple and, what I considered, idiomatic:
FROM ubuntu:21.10 AS downloader
# Install wget, gnupg; download a zip archive; verify checksum; unzip the binary
FROM ubuntu:21.10
LABEL ...
COPY --from=downloader /bin/ /bin/
RUN apt-get update && apt-get install -y openssl dumb-init iproute2 ca-certificates
&& rm -rf /var/lib/apt/lists/*
&& chmod +x /bin/
&& mkdir -p
&& ...
...
I checked the history of the image to see the size of individual layers. The problem became very apparent…
$ podman history vamc19/nomad:latest
ID CREATED CREATED BY SIZE COMMENT
...
36 minutes ago /bin/sh -c apt-get update && apt-get insta... 94.4 MB
374515aec770 36 minutes ago /bin/sh -c # (nop) COPY file:6dbfa42743cc65... 87.7 MB
22cd380ad224 36 minutes ago /bin/sh -c # (nop) LABEL maintainer="Vamsi"... 0 B FROM docker.io/library/ubuntu:21.10
...
The layer created by COPY
is 87.7MB, which is exactly the size of the extracted binary. So, that is normal. Why is the
layer created by RUN
94.4MB? What am I doing i