From 6cc2ef84991a21fe03e7299e7d583e1694facf0e Mon Sep 17 00:00:00 2001 From: Peter Solymos Date: Tue, 9 Jul 2024 02:16:36 -0600 Subject: [PATCH] Add minimal alpine image Signed-off-by: Peter Solymos --- r-shiny/Dockerfile.minimal | 34 ++++++++++++++++++++++++++++++++++ r-shiny/README.md | 23 ++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 r-shiny/Dockerfile.minimal diff --git a/r-shiny/Dockerfile.minimal b/r-shiny/Dockerfile.minimal new file mode 100644 index 0000000..761f3d1 --- /dev/null +++ b/r-shiny/Dockerfile.minimal @@ -0,0 +1,34 @@ +# Define the parent image +FROM rhub/r-minimal:4.4.1 + +# Install dependencies +# -d install C and C++ compilers, temporarily +# -t install Alpine packages, temporarily +# -a install Alpine packages and keep them +RUN installr -d \ + -t "zlib-dev cairo-dev" \ + -a "cairo font-liberation" \ + Cairo \ + shiny + +# Add non-root user and group +RUN addgroup --system app && \ + adduser --system --ingroup app app + +# Set working directory to home of the non-root user +WORKDIR /home/app + +# Copy Shiny app files +COPY app . + +# Set owner for the home folder +RUN chown app:app -R /home/app + +# Set user to non-root +USER app + +# Expose port +EXPOSE 3838 + +# Set command to execute at runtime +CMD ["R", "-e", "shiny::runApp(host='0.0.0.0', port=3838)"] diff --git a/r-shiny/README.md b/r-shiny/README.md index b8acd15..75dcfb1 100644 --- a/r-shiny/README.md +++ b/r-shiny/README.md @@ -20,7 +20,8 @@ docker pull ghcr.io/h10y/faithful/r-shiny:latest docker run -p 8080:3838 ghcr.io/h10y/faithful/r-shiny:latest ``` -Containerized version: +Containerized version using `rocker/r2u` +[image size: 909MB, build time: 16 sec] ```bash # Change directory @@ -38,3 +39,23 @@ docker build -t $TAG . # Run image, visit http://localhost:8080 docker run --rm -p 8080:3838 $TAG ``` + +Using `rhub/r-minimal` from . +[Image size: 113MB, build time: 5 min] + +```bash +# Change directory +cd r-shiny + +# If on MacOS X, set this +export DOCKER_DEFAULT_PLATFORM=linux/amd64 + +# Specify tag +export TAG=faithful/r-shiny:minimal + +# Build image +docker build -t $TAG -f Dockerfile.minimal . + +# Run image, visit http://localhost:8080 +docker run --rm -p 8080:3838 $TAG +``` \ No newline at end of file