This article explains how to reduce Docker image size by doing things like:
Adding a .dockerignore
file to exclude unnecessary files and dirs
Clearing the apt cache
Using --mount=type=cache
Changing the Dockerfile
to use smaller base images
Using multi-stage builds to exclude unnecessary artifacts from earlier stages in the final image