Creating scripts are easy. But creating a small docker image is not 😅.
Not all Linux flavors are created equal, some are bigger than others, etc. But this difference is very crucial when it comes to reducing docker image size.
A simple bash script docker image
Given a Dockerfile (change apk
to apt
for ubuntu
):
FROM alpine:3
WORKDIR /app
RUN apk update && apk add jq curl
COPY water-cut-notify.sh ./
ENTRYPOINT ["sh", "/app/water-cut-notify.sh"]
Base image | Docker image size |
---|---|
alpine | 11.1MB |
ubuntu | 122MB |
Ubuntu image size is 1099%
larger!!!!!!
What about a light python image?
FROM python:3.9-alpine
WORKDIR /app
RUN pip install requests
Base image | Docker image size |
---|---|
alpine | 53.6MB |
ubuntu | 920MB |
Ubuntu image size is 1716%
larger!!!!!!
Should you use alpine image for everything?
From above two experiments, we get:
It’s obvious that alpine has a very significant lighter footprint than ubuntu. But don’t use alpine image for everything. For bash and go, using alpine results in lighter footprint. But for python apps, it’s better to go with debian-based images. This article explains in details why it’s so.