It is getting a bit off-topic indeed. Nevertheless, the image should not be bigger if it has the same packages. Two issue I can think of., and a third that @michaelmayer told me about.
First is, pak installs system dependencies automatically, but it might install some system packages that are not needed, especially if you are using binaries from PPM. That's because if installs the build-time dependencies as well, but if you are installing binaries, then only the run-time dependencies are needed. If you are already taking care of system dependencies, then set
ENV PKG_SYSREQS=false
(Cf. [1]).
Second is that pak caches metadata and package downloads. Unfortunately there is no way currently to turn off the cache globally, but you can delete it in the same Docker step that you are using pak from, with
RUN ... && R -q -e 'pak::cache_clean(); pak::meta_clean(TRUE)'
Third is that pak leaves behind some files in /tmp
, you can delete them with rm -rf /tmp/*
in the same Docker step.
Here is an example. Using ghcr.io/r-lib/rig/ubuntu:latest
, because it already has pak, I have three Dockerfile
s, the first:
FROM --platform=linux/amd64 ghcr.io/r-lib/rig/ubuntu:latest
RUN R -q -e 'pak::pkg_install("tidyverse")'
The second:
FROM --platform=linux/amd64 ghcr.io/r-lib/rig/ubuntu:latest
RUN R -q -e 'pak::pkg_install("tidyverse"); pak::cache_clean(); pak::meta_clean(TRUE)' && \
apt-get clean
(You don't need the apt-get clean
if you turn off the sysreqs.)
Third:
FROM --platform=linux/amd64 ghcr.io/r-lib/rig/ubuntu:latest
RUN R -q -e 'pak::pkg_install("tidyverse"); pak::cache_clean(); pak::meta_clean(TRUE)' && \
apt-get clean && \
rm -rf /tmp/*
I get these (compressed) image sizes:
EDIT: @michaelmayer is telling me that pak also leaves files in /tmp
, so I added the third Dockerfile
.
[1] Environment variables and options that modify the default behavior — pak configuration • pak