-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
The r-base image has been refactored to implement a multi-stage build pattern and enforce non-root user execution, significantly improving image security, size, and build efficiency with 7d6f819.
Changes Implemented
| Feature | Description | Benefit |
|---|---|---|
| Multi-Stage Build | Separated the build environment (Stage 1: builder) from the runtime environment (Stage 2: final). |
Drastic reduction in final image size by discarding build dependencies (e.g., autoconf, cmake, apt caches) and improving layer caching. |
| Non-Root User | Created a dedicated unprivileged user, user (UID 1000/GID 1000), for container runtime. The user is added to the staff group (see rocker) to ensure write access to /usr/local/lib/R/site-library. |
Adheres to the Principle of Least Privilege, significantly mitigating potential security risks if code is exploited at runtime. |
| Dependency Management | Ensured only necessary runtime scripts (build.R, check.R, validate-settings.R, etc.) and installed packages are carried over to the final image. |
Further reduces image size and tightens security by removing build-only clutter. |
Image Size Reduction
The multi-stage refactoring resulted in a significant reduction in the final image size, demonstrating a tangible efficiency gain.
| Image Repository | Tag | Image ID | Size | Change vs. Old Build |
|---|---|---|---|---|
rocker/r-ver |
4.5.1 (Base Image) |
c71059b67e6a |
948MB | - |
inwt/r-base |
4.5.1 (Old Build) |
4c69c1c07c7c |
1.33GB | - |
inwt/r-base |
4.5.1.non-root (New Multi-Stage) |
9148f94c81e8 |
1.07GB | -260MB (20% reduction) |
Action Required for Dependent Images
All downstream images:
-
r-batch -
r-shiny -
r-model -
r-geos
must now be updated to use the same multi-stage pattern, starting FROM inwt/r-base:4.5.1 and explicitly enforcing the non-root user for package installation and runtime.
The recommended pattern is:
- Stage 1 (
<name>-builder):FROM inwt/r-base:4.5.1 - Run as
rootto install any new system dependencies (apt-get). - Switch to
userto install R packages. - Stage 2 (
final-<name>):FROM inwt/r-base:4.5.1 COPY --fromthe newly installed R packages and other artifacts.USER userfor final execution.
Metadata
Metadata
Assignees
Labels
No labels