Jupyter Notebook containerized with Singularity

By Staff

Oct 2, 2018 | Blog, How To Guides

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

    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

    #Create the .condarc file where the environments/channels from conda are specified, 
    #these are pulled with preference to root
    cd /
    touch .condarc

    #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 \

   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

  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= --port=9000

This will run Jupyter Notebook on

For the files used in this example, see our GitHub repository at:

If you have any questions or comments related to the information covered in this blog, connect with us! You can join our SingularityCE Slack Channel, connect with us on Google Groups, or start a discussion on GitHub! We can also be found on X at @Sinuglarity_CE. Whatever your preference, we are here to help and would be happy to take suggestions for future posts.

Join Our Mailing List

Recent Posts

Related Posts

Remote Building with OCI Registries

This blog post will demonstrate how to use a definition file in a remote build that references an Open Container Initiative (OCI) image stored in Singularity Enterprise and Singularity Container Services.First, create an account in Singularity Container Service. To do...

read more