Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

singularity_docker_jupyter

  • Clone with SSH
  • Clone with HTTPS
  • Name Last commit Last update
    docker
    .gitignore
    README.md

    singularity_docker_jupyter

    In this recipe, you will learn how to create your own container-based environment that you can use at home on on the supercomputer. It is compatible with windows as well as Linux and MacOS, however only if your host is of X86 architecture (new Macs might pose a problem).
    It is composed of the following steps: 0. Install docker

    1. Create a docker container that contains the environment
    2. Run the docker container to serve a local jupyter server and to execute programs
    3. Export the docker container for singularity. (Does this work on WSL?)
    4. Recreate the environment on the supercomputers

    #Install docker This step depends on the OS you use. Please follow the instructions on the docker web page. After that you should be able to start a simple docker container:

    docker run -it ubuntu bash

    You can leave the container by typing exit.

    On Windows, it is highly recommended to install the Windows Subsystem Linux. This will provide you with the WSL console, where you have a linux-like environment. Please check that you can execute the commands above.

    For convenience, we recommend enabling the option to run docker without the sudo command. On Linux, you can follow this procedure. Otherwise, you will need to adjust the scripts in the docker subdirectory.

    Create a docker image and container

    In this step, you will create a custom docker image and a docker container that contains the environment. First clone this repository, and cd into it. Please pick a good path for that. You might keep this repository for a long time. Here we assume, it is /path/to.

    cd /path/to
    git clone https://gitlab.jsc.fz-juelich.de/AI_Recipe_Book/recipes/singularity_docker_jupyter
    cd singularity_docker_jupyter

    Everything related to the docker image is in the subdir docker. The rules to build the docker image are found in the Dockerfile. Look inside, you will see that we start from a plain ubuntu-image, install Python with apt-get and install Jupyter with pip. Build the docker container with the following commands

    cd docker
    ./build.sh

    The build script will build the container and tag it with singularity_docker_jupyter. Once the container is build, you can run the jupyter server with the script run.sh:

    ./run_jupyter.sh

    The run script will start a docker container hosting a jupyter server that you can access by navigating to http://localhost:8889/. It will be restarted automatically when your system reboots or the container exits. In order to permanently remove it, execute

    docker rm -f singularity_docker_jupyter_cont

    We also have created small scripts to run commands and an interactive shell in the container. Execute

    ./run_bash_in_container.sh

    to run an interactive bash shell inside of the container. Exit it by typing exit. Executing commands is possible with the script run_command_in_container.sh. If you execute

    ./run_command_in_container python3 --version

    you will see which python version has been installed into the container.

    Export the docker container for singularity

    In this step, you will export the docker image you have created as a singularity container. It requires the following steps:

    1. Save the docker image in a tarball
    docker save singularity_docker_jupyter -o singularity_docker_jupyter.tar
    1. Copy the image to one of the JSC machines:
    scp singularity_docker_jupyter.tar surname1@jusuf.fz-juelich.de:/path/to/image

    Note that this can take a while, depending on your connection.

    1. ssh to the machine and convert the tarball into a singularity image.
    ssh surname1@jusuf.fz-juelich.de
    cd /path/to/image
    singularity build singularity_docker_jupyter.sif docker-archive://singularity_docker_jupyter.tar

    If you local machine is a Linux machine, you also have the option to create the singularity image singularity_docker_jupyter.sif on your local machine.

    Execute the container with singularity on the supercomputer

    Details about the container is started

    The script run_jupyter.sh does a few things that are untypical when using docker. Here are the most important points.

    • We do not store any information in the container. Your home directory is mounted into the container. This is done by using -v $HOME:$HOME. It is mounted to the same path as on the host computer. This ensures not path inconsistencies occur.
    • The HOST environment variable is exported into the container. This is done with the option -e HOME
    • The user id and group id are not set to root/0 as typical for docker, but with the option --user $(id -u $USER):$(id -g $USER) we make sure that UID and GID inside the container are the same as the ones of the user who starts the container. All files modified in the container will be accessed with the UID and GID of the same user. If you are the only user, you will not even realize you are inside a container.
    • The port 8888 of the container is mapped to the port 8889 of your local computer. The jupyter server started in the container by default serves on port 8888. To avoid conflicts with another potentially running jupyter environment on your local machine, the container-based server serves on port 8889.
    • The container is given the name singularity_docker_jupyter_cont

    We start the jupyter server with a few options

    • We don't restrict IPs that can use the server
    • We don't open a browser
    • We disable access tokens
    • We use the $HOME directory as base directory for the jupyter server.