8000 Remove headers to reduce image size · Issue #42 · r-hub/r-minimal · GitHub
[go: up one dir, main page]

Skip to content

Remove headers to reduce image size #42

Open

Description

@artemklevtsov

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

Activity

  1. gaborcsardi commented on Mar 18, 2022

    @gaborcsardi
    Collaborator

    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.

  2. gaborcsardi commented on Dec 12, 2023

    @gaborcsardi
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0