How to containerIze your jupyter kernel?

We have seen in this blog post how to encapsulate a jupyter notebook (server) in a singularity container . In this tutorial, I am going to describe how you can run a jupyter kernel in a container and make it available in the jupyter*.

Possible use case for this is to install a supported PyTorch version and work with jupyter notebooks (see GLIBC and the container-based workaround).


Please, check this tutorial for more details to run singularity containers on Mistral. Some optimization might be necessary for CACHE and TEMP.


  • singularity image compatible with Mistral (RHEL6)

  • software packages

  • ipykernel

  • kernel.json


How it works?

The concept is simple, usually, software packages are located in conda/venv environements somwhere in Mistral’s file system. The idea is to allow working with packages from a singularity container.

Pull the image

There are lot of a predefined images with installed software packages. You don’t need to build it from scratch. These images must be supported on Mistral.

In this tutorial, I am using this image with the following software packages:

  • jupyter

  • jupyterlab

  • matplotlib

  • pandas

  • ipykernel

  • xarray

  • intake-esm

  • intake-xarray

You need to download this image to your (default) HOME directory on MIstral.

# load singularity module
module load singularity
# pull the image
singularity pull library://lev-hpc/jupyter/jupyter-kernel:latest



chmod +x

The content should look like this:


source /etc/profile
module purge

module load singularity

singularity exec --cleanenv /full/path/to/jupyter-kernel_latest.sif python -m ipykernel_launcher -f "$1"

Create kernel.json

You need a kernel configuration file:

module load python3/unstable

python -m ipykernel install --user --name singularity-kernel --display-name="singularity-kernel"

This file must be modified to enable the connection to the singularity container. My favorite method is via a bash script (let’s name it

 "argv": [
 "display_name": "singularity-kernel",
 "language": "python"

Without a bash script

If you like to write all modifications in kernel.json:

 "argv": [
 "language": "python",
 "display_name": "singularity-kernel"