Let’s say you have a Dockerfile
FROM ubuntu:20.04
RUN apt-get install -y curl
You build an image with it
docker build -t my-curl-image
and run it
docker run -itd --rm --name my-container my-curl-image
Now you have an Ubuntu container with curl installed.
This works just fine with simple requirements. But, what if you needed to install something or you have to compile a certain packages. More often than not this involves installing development packages. Packages that you no longer need once you build something.
When running on a typical system you’re less resource constrained, you can afford to have gcc
installed for the convenience of not having to install it again. However when running on a remote service such as Azure Function apps, AWS Lambda or even your VPS this becomes important.
Suddenly, you’re trying to reduce the size of each layer.
Now you have a docker image with curl installed