RShiny base image
Dockerfile
add a point on the format of packages_to_install.csv, and how we install it
In this part, we will described the specific Dockerfile for R.
Dockerfile.r
Here the content of the Dockefile.r
1# Build image from base image `ubuntu`
2FROM ubuntu:${UBUNTU_VERSION}
3
4# define geographic location during R installation
5ENV TZ=Etc/UTC
6ENV DEBIAN_FRONTEND=noninteractive
7ENV SHINY_LOG_STDERR=1
8
9EXPOSE 3838
10CMD ["shiny-server"]
11
12# install dependencies
13RUN apt-get update \
14&& apt-get install -y \
15 nano \
16 wget \
17 curl \
18 lsb-release \
19 libcurl4-openssl-dev \
20 gcc \
21 gfortran \
22 g++ \
23 libreadline-dev \
24 zlib1g-dev \
25 libbz2-dev \
26 liblzma-dev \
27 libpcre2-dev \
28 libcairo-dev \
29 libpng-dev \
30 libicu-dev \
31 libxml2-dev \
32 libssl-dev \
33 make \
34 libtiff-dev \
35 xorg-dev \
36 libx11-dev \
37&& rm -rf /var/lib/apt/lists/*
38
39# Copy only this installation script so new R package won't invalidate it installation
40COPY ./scripts/install_r_cran.sh /opt/scripts/install_r_cran.sh
41
42# Copy the R archive is already present, otherwise it will be downloaded
43# COPY ./R*.tar.gz /tmp/
44
45ARG R_VERSION=latest
46# Install R, along with its dependencies
47RUN /opt/scripts/install_r_cran.sh
48# Test R in another layer
49RUN R -q -e "sessionInfo(); capabilities()"
50
51# Copy the remaining scripts
52COPY ./scripts /opt/scripts
53
54ARG SHINY_SERVER_VERSION=latest
55# Install R packages included Shiny, then install shiny server
56RUN /opt/scripts/configure_Rprofile.sh \
57&& Rscript /opt/scripts/install_r_packages.R
58RUN /opt/scripts/install_shiny_server.sh
59
60# allows trafic from all ips
61RUN sed -i "s/3838/3838 0.0.0.0/g" /etc/shiny-server/shiny-server.conf
62
63# grant shiny to created bookmark state directory in /var/lib/
64# grant shiny to write logs in /var/log/
65# grant shiny to write in /srv/shiny-server/www/
66RUN chown shiny:shiny /var/lib/shiny-server \
67&& mkdir -p /var/log/shiny-server \
68&& chown shiny:shiny /var/log/shiny-server \
69&& mkdir -p /srv/shiny-server/www \
70&& chown shiny:shiny /srv/shiny-server/www
Line 2: The base image
1# Build image from base image `ubuntu`
2FROM ubuntu:focal
The FROM ...
indicate which base image should be used, the image contains:
an OS, here ubuntu, either focal (LTS 20.04) or jammy (LTS 22.01)
R’s “shiny” package
the shiny-server
In the gitlab-ci.yml
, we decide to provide selected version of R base image based on several R version
and compatible with kubernetes architecture deployed at Pasteur. Actually (Sept. 2023), three versions are available and mentionned
in the file gitlab-ci.yml`, as you can see extract below :
1...
2 - LANGUAGE: ["r"]
3 R_VERSION: [
4 "3.6.3",
5 "4.2.3",
6 "4.3.1",
7 ]
8
9...
For more details about gitlab-ci.yml
, please see the dedicated pages for gitlab-ci.yml.
Lines 5-7 : Environment variables
4# Define geographic location during installation
5ENV TZ=Etc/UTC
6ENV DEBIAN_FRONTEND=noninteractive
7ENV SHINY_LOG_STDERR=1
Some environment variables need to be defined in the container and set parameters needed for shiny-server installation or configuration.
Here, we set :
line 5 : the System Timezone
TZ
toEtc/UT
line 6 : the debconf frontends (interaction with the debconf interface)
DEBIAN_FRONTEND
tononinteractive
.noninteractive
permit to have zero interaction while installing or upgrading the system via apt.line 7 : the standard error output
SHINY_LOG_STDERR
to a non-empty value1
. To saving individual process logs to disk, Shiny Server can also relay those logs to its own stderr (which, by default, is saved to /var/log/shiny-server.log).
Line 9 : Listen port for Shiny-server
9EXPOSE 3838
By default, Shiny Server listens on port 3838, so the default application will be available at http://<server-address>:3838.
We decide to conserve the default port mentionned in the /etc/shiny-server/shiny-server.conf
, configuration file of shiny-server.
The EXPOSE
instruction informs Docker that the container listens on the specified network ports at runtime.
So, here we indicate the 3838
listen port.
Warning
/etc/shiny-server/shiny-server.conf
.Line 10 : Run Shiny-server
10CMD ["shiny-server"]
The main purpose of a CMD
is to provide defaults for an executing container.
Here, CMD ["shiny-server"]
permits to launch the shiny-server, normally run by the command line shiny-server
.
Thanks to CMD
, the shiny-server will be launch by default when the container will be run.
Note
Threre can only be one CMD
instruction in a Dockerfile.
Lines 13-37 : The system dependencies
12# Install dependencies
13RUN apt-get update \
14&& apt-get install -y \
15 nano \
16 wget \
17 curl \
18 lsb-release \
19 libcurl4-openssl-dev \
20 gcc \
21 gfortran \
22 g++ \
23 libreadline-dev \
24 zlib1g-dev \
25 libbz2-dev \
26 liblzma-dev \
27 libpcre2-dev \
28 libcairo-dev \
29 libpng-dev \
30 libicu-dev \
31 libxml2-dev \
32 libssl-dev \
33 make \
34 libtiff-dev \
35 xorg-dev \
36 libx11-dev \
37 && rm -rf /var/lib/apt/lists/*
Shiny-server require some system dependencies.
Here, we use the apt-get
command line in order to install all dependencies requiered in the container.
Note
You can add system packages will be requiered by your future shiny app but don’t delete one in these previous list.
Lines 40-49 : Installation of R
41# Copy only this installation script so new R package won't invalidate it installation
42COPY ./scripts/install_r_cran.sh /opt/scripts/install_r_cran.sh
43
44# Copy the R archive is already present, otherwise it will be downloaded
45# COPY ./R*.tar.gz /tmp/
46
47ARG R_VERSION=latest
48# Install R, along with its dependencies
49RUN /opt/scripts/install_r_cran.sh
50# Test R in another layer
51RUN R -q -e "sessionInfo(); capabilities()"
/opt/scripts/install_r_cran.sh
file.More details about this bash script install_r_cran.sh
in the helper script section
Lines 51-57 : Install R Packages
51# Copy the remaining scripts
52COPY ./scripts /opt/scripts
53
54ARG SHINY_SERVER_VERSION=latest
55# Install R packages included Shiny, then install shiny server
56RUN /opt/scripts/configure_Rprofile.sh \
57&& Rscript /opt/scripts/install_r_packages.R
scripts
(files available in shiny-k8s gitlab project).SHINY_SERVER_VERSION
to value latest
.configure_Rprofile.sh
and R script install_r_packages.R
.configure_Rprofile.sh
in the helper script sectioninstall_r_packages.R
in the helper script sectionLine 58 : Installation Shiny Server
58RUN /opt/scripts/install_shiny_server.sh
The instruction line 58 just run the bash script install_shiny_server.s
More details about the bash script in the helper scripts section
Line 61 : Custom Shiny-server configuration file
60# Allows trafic from all ips
61RUN sed -i "s/3838/3838 0.0.0.0/g" /etc/shiny-server/shiny-server.conf
In order to access correctly to your app, we set again the listen port in the specific configuration file of shiny-server.
The line 61 permits to set the chosen values in the /etc/shiny-server/shiny-server.conf
Lines 66-70 : Permissions
63# Grant shiny to created bookmark state directory in /var/lib/
64# Grant shiny to write logs in /var/log/
65# Grant shiny to write in /srv/shiny-server/www/
66RUN chown shiny:shiny /var/lib/shiny-server \
67&& mkdir -p /var/log/shiny-server \
68&& chown shiny:shiny /var/log/shiny-server \
69&& mkdir -p /srv/shiny-server/www \
70&& chown shiny:shiny /srv/shiny-server/www
By default, Shiny Server will create and store data in /var/lib/shiny-server/
.
instruction line 57 permits to allow the user shiny
to write in this dedicated folder.
All information related to Shiny Server itself, rather than a particular Shiny application, is logged in the global system log stored in /var/log/shiny-server.log.
This log should be checked often to ensure Shiny Server is performing as expected. Any errors and warnings that Shiny Server needs to communicate will be written here.
In order to access these log files, we grant the user shiny
to write in the dedicated folder (lines 66-70).
In order to share easily data with the futur user of the shiny app, we add instruction to allow user shiny
to access at /srv/shiny-server/www
folder.
Note
More details about the content of Dockerfile in Dockerfile reference