Adapting the Dockerfile to your needs

Here, you can see the content of the Dockerfile:

  • Python
  • R
 1# Build image from the base image, previously configured for you
 2FROM registry-gitlab.pasteur.fr/hub/shiny-k8s/python:3.9-slim-bullseye
 3
 4# Add workdir information
 5WORKDIR /srv/shiny-server/
 6
 7# install additional dependencies, comment the block if you don't have one
 8RUN apt-get update \
 9&& apt-get install -y \
10        wget \
11&& rm -rf /var/lib/apt/lists/*
12
13# Copy your dependencies, destination filename must be "packages_to_install.csv"
14COPY ./requirements.txt /opt/scripts/requirements.txt
15
16# Install Python packages
17RUN pip install -r /opt/scripts/requirements.txt
18
19# grant shiny to created bookmark state directory in this directory
20RUN chown shiny:shiny /var/lib/shiny-server
21
22# Copy you shiny app
23COPY ./my_project /srv/shiny-server
24
25# grant shiny to use www folder
26RUN chown shiny:shiny /srv/shiny-server/www
 1# Build image from the base image, previously configured for you
 2FROM registry-gitlab.pasteur.fr/hub/shiny-k8s/r:4.3.1
 3
 4# Add workdir information
 5WORKDIR /srv/shiny-server/
 6
 7# install additional dependencies, comment the block if you don't have one
 8RUN apt-get update \
 9&& apt-get install -y \
10        wget \
11&& rm -rf /var/lib/apt/lists/*
12
13# Copy your dependencies, destination filename must be "packages_to_install.csv"
14COPY ./my_packages_to_install.csv /opt/scripts/packages_to_install.csv
15
16# Install R packages
17RUN Rscript /opt/scripts/install_r_packages.R
18
19# grant shiny to created bookmark state directory in this directory
20RUN chown shiny:shiny /var/lib/shiny-server
21
22# Copy you shiny app
23COPY ./my_project /srv/shiny-server
24
25# grant shiny to use www folder
26RUN chown shiny:shiny /srv/shiny-server/www

Line 1: The base image, with the right version

  • Python
  • R
1# Build image from the base image, previously configured for you
2FROM registry-gitlab.pasteur.fr/hub/shiny-k8s/python:3.9-slim-bullseye
1# Build image from the base image, previously configured for you
2FROM registry-gitlab.pasteur.fr/hub/shiny-k8s/r:4.3.1

The FROM ... indicate which base image should be used, the image contains:

  • an OS with python or R, depends of your shiny app

  • python’s or R “shiny” package

  • the shiny-server

We provide various version of R and Python for your needs, here is a list (as of september 2023).

  • registry-gitlab.pasteur.fr/hub/shiny-k8s/r:3.6.3

  • registry-gitlab.pasteur.fr/hub/shiny-k8s/r:4.2.3

  • registry-gitlab.pasteur.fr/hub/shiny-k8s/r:4.3.1

  • registry-gitlab.pasteur.fr/hub/shiny-k8s/python:3.9-slim-bullseye

  • registry-gitlab.pasteur.fr/hub/shiny-k8s/python:3.10-slim-bullseye

  • registry-gitlab.pasteur.fr/hub/shiny-k8s/python:3.11-slim-bullseye

Up to date list can be found in https://gitlab.pasteur.fr/hub/shiny-k8s/container_registry

For more details about base images, please see the dedicated pages for python and R.

Line 5: Working Directory

  • Python & R
4# Add workdir information
5WORKDIR /srv/shiny-server/

We set the current working directory to /srv/shiny-server/ .

Lines 8-11: The system dependencies

  • Python & R
 7# install additional dependencies, comment the block if you don't have one
 8RUN apt-get update \
 9&& apt-get install -y \
10        wget \
11&& rm -rf /var/lib/apt/lists/*

Some of your package dependencies require system dependencies (such as graphviz-dev for pygraphviz).

To add such dependencies, duplicate line 10, and replace wget with your dependencies.

If you have no additional system dependencies you can remove this block.

Lines 14-17: The package dependencies

  • Python
  • R
13# Copy your dependencies, destination filename must be "packages_to_install.csv"
14COPY ./requirements.txt /opt/scripts/requirements.txt
15
16# Install Python packages
17RUN pip install -r /opt/scripts/requirements.txt
13# Copy your dependencies, destination filename must be "packages_to_install.csv"
14COPY ./my_packages_to_install.csv /opt/scripts/packages_to_install.csv
15
16# Install R packages
17RUN Rscript /opt/scripts/install_r_packages.R

The package dependencies are copied into the images line 14, and installed line 17. The format of the file listing the dependencies depends on the language you use:

Python: requirements.txt

This file is the default file for dependencies in python. You can specify package, with or without a specific version, install from a git. The syntax to respect is the following :

sphinx=~7.0.1
sphinx_rtd_theme
git+https://gitlab.pasteur.fr/user/some-project.git@v1.3

By default, in the gitlab project shiny-k8s-example, the python packages mentionned in the requirements.txt file are shiny and htmltools.

shiny
htmltools

You are free to modify this list. shiny package is already installed in the previous base image, created at shiny-k8s level.

R: my_packages_to_install.csv

In this file you list in csv file the packages (with ; as separator). For each file, how it can be found is specified in the second column. If can be from cran, from bioconductor, or even a github package.

Package_name;Comments
shinythemes;cran package
ggplot2;cran package
limma;bioconductor package
tidyverse/tibble; github package

Line 20: Grant shiny to create bookmark state

  • Python & R
19# grant shiny to created bookmark state directory in this directory
20RUN chown shiny:shiny /var/lib/shiny-server

In order to run your application, the user shiny must be allow to write file in /var/lib/shiny-server directory .

Line 23: Copy your app into the image

  • Python & R
22# Copy you shiny app
23COPY ./my_project /srv/shiny-server

At that moment you copy you app in the image. Keep in mind that this folder name can be adapted.

Line 26: Grant shiny to write output data

  • Python & R
25# grant shiny to use www folder
26RUN chown shiny:shiny /srv/shiny-server/www

When your application produce files, they are written in www directory, thus this directory must be own by user shiny , the user who will run the app.