Maintaining Open Source Singularity Since 2017
Jupyter Notebook containerized with Singularity
By Adam Hughes
Jupyter Notebook is an open source web application environment used to create and share documents containing code, equations, visualizations and narrative text. Use cases include data visualization, statistical modeling and machine learning.
Singularity provides a basis for repeatability with a container runtime that does not require root owned daemon or allow escalation of user privilege when ran. With it’s single file image format (SIF) Singularity is ideal for BYOE science (bring your own environment) and for the mobility of compute with deep learning applications.
We’ll use the following Singularity definition file when building Jupyter:
Bootstrap: library
From: debian:9
%help
Container with Anaconda (Conda 4.5.11) and Jupyter Notebook 5.6.0 for Debian 9.x (Stretch).
This installation is based on Python 2.7.15
%setup
#Create the .condarc file where the environments/channels from conda are specified,
#these are pulled with preference to root
cd /
touch .condarc
%post
#Installing all dependencies
apt-get update && apt-get -y upgrade
apt-get -y install \
build-essential \
wget \
bzip2 \
ca-certificates \
libglib2.0-0 \
libxext6 \
libsm6 \
libxrender1 \
git
rm -rf /var/lib/apt/lists/*
apt-get clean
#Installing Anaconda 2 and Conda 4.5.11
wget -c https://repo.continuum.io/archive/Anaconda2-5.3.0-Linux-x86_64.sh
/bin/bash Anaconda2-5.3.0-Linux-x86_64.sh -bfp /usr/local
#Conda configuration of channels from .condarc file
conda config --file /.condarc --add channels defaults
conda config --file /.condarc --add channels conda-forge
conda update conda
#List installed environments
conda list
%runscript
jupyter notebook --allow-root "$@"
To build the image run the following command:
$ sudo singularity build jupyter.sif jupyter.def
The definition file above has a %post section in which all the dependencies are installed at build time. After that, you can start the container and, it will listen on localhost:8888 by default.
$ singularity run jupyter.sif
If you would like to run it on another port (e.g. 9000) instead you can do so by:
$ singularity run jupyter.sif --port=9000
This will run Jupyter Notebook on localhost:9000.
And if you would like to set another hostname use ––ip when running the image:
$ singularity run jupyter.sif --ip=1.1.1.1 --port=9000
This will run Jupyter Notebook on 1.1.1.1:9000
For the files used in this example, see our GitHub repository at:
https://github.com/sylabs/examples/tree/master/machinelearning/jupyter-notebook
Join Our Mailing List
Recent Posts
Related Posts
Laying the Groundwork for 2025: Sylabs’ Vision for Secure Multi-Cloud Solutions
With a legacy rooted in innovation through the work we’ve done with the Singularity platform, Sylabs has consistently worked to provide secure container technology to empower researchers, enterprises, and innovators worldwide. These efforts have paid dividends as we...
Creating New Levels of Security with Containers and Confidential Computing
Data breaches are becoming increasingly common. It's more important than ever to find robust solutions that protect sensitive information. Recent high-profile data breaches underscore the necessity for fresh approaches to data protection. Breaches like these are...
OCI-SIF Container Images: Unraveling Their Features and Benefits
Among the container industry, OCI (Open Container Initiative) and SIF (Singularity Image Format) stand out as two prominent formats, each offering unique features and benefits. Understanding their distinct characteristics is crucial for HPC developers seeking optimal...