This is an extension to this post about creating a kernel in a Jupyter notebook that runs a Singularity container.
Download Singularity (see here).
Create a Singularity
file, e.g., (making sure to install the ipykernel
module in it):
Bootstrap: docker
From: ubuntu:xenial
%runscript
echo "Hello... I am a new Singularity container"
%labels
AUTHOR [email protected]
%post
apt-get update && apt-get install -y python-pip python-dev build-essential
pip install --upgrade pip
pip install --trusted-host pypi.python.org numpy
pip install --trusted-host pypi.python.org ipykernel
Build the image with:
sudo singularity build --writable test.simg Singularity
where the --writable
command is important.
Create jupyter notebook kernel using the image. To do this,
in the ${HOME}/.local/share/jupyter/kernels
create a new directory, e.g. myimage
, and add a kernel.json
file containing:
{
"language": "python",
"argv": ["/usr/bin/singularity",
"exec",
"-w",
"/home/matthew/singularity/test.simg",
"/usr/bin/python",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"display_name": "Python 2 (Singularity)"
}
where adding the -w
option is important. Then start a jupyter notebook with
jupyter notebook &
and there should be a usable Python 2 (Singularity)
kernel option!