r-minimal
r-minimal copied to clipboard
Remove headers to reduce image size
We can reduce image size if remove all C/C++ headers from the include
directories. For example, BH size is 126 Mb.
Note, only the final image can be optimized this way because headers no needs anymore.
My suggestion is to add the following command to the end of the examples (and FAQ):
rm -rf ~/.cache/* && \
rm -rf /var/cache/apk/* && \
find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.h' -delete && \
find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.hpp' -delete
Also consider to clean up doc and html, localization files directories in the /usr/local/lib/R/library
.
Results.
Example 1:
FROM rhub/r-minimal:4.1
RUN installr -d RcppUUID
❯ docker build --no-cache -t test1 .
❯ docker image ls | grep test1
test1 latest 2de64ed9d50c 29 seconds ago 174MB
Example 2
FROM rhub/r-minimal:4.1
RUN installr -d RcppUUID && \
find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.h' -delete && \
find /usr/local/lib/R/library/ -type f -path '*/include/*' -name '*.hpp' -delete
❯ docker build --no-cache -t test2 .
❯ docker image ls | grep test2
test2 latest 100b444eb7ec 3 seconds ago 44.3MB
Update:
Also *.mo
, *.pdf
files can be removed:
find /usr/local/lib/R/library/ -type f -path '*/po/*' -name '*.mo' -delete
find /usr/local/lib/R/library/ -type f -path '*/doc/*' -name '*.pdf' -delete
Yeah, we could have one or more switches in installr
to do this.
The main downside of course is that you might not be able to use these Dockerfiles to build other Dockerfiles, if you cannot install packages that depend on (say) BH.
Maybe a good way to achieve this would be to have an installr
option that goes over your library and cleans it up, after installation.