Topics Map > User Guides
Topics Map > Platform R

Platform R: Customizing Containers

Using pre-made containers will be fine for some workflows, but often you will want to customize an existing image. This article shows how to extend a bare R container image to include some additional libraries.

To follow along with the steps below, create a directory in your Platform R home directory or shared group space (under /mnt/scratch/group/) to hold the files.

Get a Base Image to Modify

First, start a shell session on one of the slurm compute nodes. The login node does not have the apptainer command.

srun --ntasks=1 --pty bash -i

Next, in your working directory, use the apptainer command to grab a base R container.

apptainer pull docker://git.doit.wisc.edu/smph/smph-it/informatics/infrastructure/platform-r/dependency_proxy/containers/r-base:4.5.1

After this finishes you will have the file r-base_4.5.1.sif in your directory.

Create Definition File

Create a file called myR.def to describe the changes you want to make to the base container.

Bootstrap: localimage
From: r-base_4.5.1.sif

%post
  R -e "install.package('foreach')"
 R -e "install.package('doFuture')"

%labels
  Author Your Name
 Version 1.0
  Description R 4.5.1 with doFuture parallelization.

This definition file first tells Apptainer that the image will be a modification of a local image, the basic R container downloaded in the previous step, then has some shell commands in the %post section which add two libraries. Finally you can include some metadata about the container.

Build the New Container

Note the order of arguments for the build command: the new SIF file name comes first, the definition file we just created comes last.

apptainer build myR.sif myR.def

You will see the output of the R install.package commands. Once the R commands are done it will take a minute or two for the new SIF to be created. It shows an updating estimation of how long it will take to complete.

Verify Your Custom Container

Start an interactive R session with the new container:

apptainer run myR.sif R

Use the R command library(doFuture) to verify that the library is available as expected.

Last Steps

Once you are sure your new container has what you need, you can delete the original base R SIF file. Also exit out of your srun session to the compute node.

Related Documentation



Keywords:
slurm, Platform R, apptainer, container 
Doc ID:
154478
Owned by:
William A. in SMPH Research Applications
Created:
2025-08-27
Updated:
2025-08-29
Sites:
SMPH Research Applications