Size of installed packages in Docker images

I’m trying to build a Julia image for a CI server that has a few packages preinstalled.
Unfortunately, my naive approach seems to install more than I need.

The layers of the base julia:1.11 image look like this

Cmp   Size  Command                                                  
     97 MB  FROM blobs                              
     15 MB  RUN /bin/sh -c set -eux; apt-get update; apt-get install -y --no-install-recommends ca-certificates curl ...
    869 MB  RUN /bin/sh -c set -eux; savedAptMark="$(apt-mark showmanual)"; apt-get update; apt-get install -y --no-install-r...
     309 B  COPY docker-entrypoint.sh /usr/local/bin/ # buildkit

So roughly 115MB for Debian+Curl, and 900MB for Julia.

Now I start adding packages, based on a Dockerfile like this

FROM julia:1.11
RUN julia -e 'import Pkg; Pkg.add(["CairoMakie"])'

and the result is an image that looks like this

Cmp   Size  Command                   
     97 MB  FROM blobs                                                    
     15 MB  RUN /bin/sh -c set -eux; apt-get update; apt-get install -y --no-install-recommends ca-certificates curl ...
    869 MB  RUN /bin/sh -c set -eux; savedAptMark="$(apt-mark showmanual)"; apt-get update; apt-get install -y --no-install-r...
     309 B  COPY docker-entrypoint.sh /usr/local/bin/ # buildkit
    1.4 GB  RUN /bin/sh -c julia -e 'import Pkg; Pkg.add(["CairoMakie"])' # buildkit  

1.4GB for Makie. An equivalent file for DifferentialEquations gives

Cmp   Size  Command                                         
     ...
    877 MB  RUN /bin/sh -c julia -e 'import Pkg; Pkg.add(["DifferentialEquations"])' # buildkit   

900MB for DifferentialEquations. Combining both in one install command still adds 2.2GB. This all seems excessive. Is there a way to slim these down/remove things I might not need?

Thanks for your help

6 Likes