Book a Demo
Book a Demo

Customize Jupyter App

Sateesh Peri

This guide explains how to install customer-specified packages using a Dockerfile and a Conda environment file.

1. Create Dockerfile

Create a file named Dockerfile with the following content:

FROM --platform=linux/amd64 continuumio/miniconda3

# Set the working directory
WORKDIR /usr/src/app

# Copy the environment.yml file to the working directory
COPY environment.yml ./

# Create a Conda environment using the environment.yml file
RUN conda env create -f environment.yml

# Ensure the Conda activation script is available
RUN echo "source activate myenv" >> ~/.bashrc

# Expose the port for JupyterLab
EXPOSE 8888

# Entry command to start JupyterLab without token authentication
ENTRYPOINT ["bash", "-c", "eval \"$(conda shell.bash hook)\" && conda activate myenv && jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' --NotebookApp.password=''"]

2. Create environment.yml

If you already have an environment.yml file, you can skip step 3. Create a file named environment.yml with the following content:

name: myenv                     # Specify the name of the Conda environment
channels:
  - conda-forge                 # A community-driven channel with a wide variety of packages
  - bioconda                    # A channel with packages specific to bioinformatics
dependencies:
  - python                      # Install Python
  - numpy                       # Install NumPy for numerical computations
  - jupyterlab                  # Install JupyterLab, an interactive development environment

Note: The above is just an example. You can replace the content in channels: and dependencies: based on your needs.

3. Export environment.yml from Existing Conda Environment

If you do not have an environment.yml file but have a Conda environment, follow these steps to generate one. Skip this step if you have completed step 2.

  • Activate your existing Conda environment:
conda activate your_existing_env
  • Export the environment to a file:
conda env export > environment.yml

The generated environment.yml file will be located in the current directory.

  • Review and edit the environment.yml file if necessary. Open the environment.yml file in a text editor and make any necessary adjustments, such as removing unnecessary packages or changing package versions.

4. Build the Docker Image

Run the following command to build the Docker image. Replace YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME with the desired name for your Docker image:

docker build -t YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME -f Dockerfile .

Example:

docker build -t cizhiwu/jupyterlab-env:v1 -f Dockerfile .

5. Tag the Docker Image

Run the following command to tag the Docker image. Replace YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME and VERSION_TAG with the appropriate values:

docker tag YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME:VERSION_TAG YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME:latest

Example

docker tag cizhiwu/jupyterlab-env:v1 cizhiwu/jupyterlab-env:latest

6.Push the Docker Image

Run the following commands to push both the versioned and latest tags to Docker Hub:

docker push YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME:VERSION_TAG
docker push YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME:latest

Example:

docker push cizhiwu/jupyterlab-env:v1
docker push cizhiwu/jupyterlab-env:latest

7. Launch JupyterLab on Opcenter

Log in to your Opcenter instance and run the following command to submit the job.

The -c flag specifies the number of CPUs, and the -m flag specifies the memory size in GB:

float submit -i docker.io/YOUR_DOCKERHUB_USERNAME/YOUR_IMAGE_NAME:latest -c 4 -m 16 --publish 8888:8888 --imageVolSize 17 --vmPolicy [onDemand=true] --migratePolicy [disable=true] --withRoot=true --securityGroup YOUR_SECURITY_GROUP

Example:

float submit -i docker.io/cizhiwu/jupyterlab-env:latest -c 4 -m 16 --publish 8888:8888 --imageVolSize 17 --vmPolicy [onDemand=true] --migratePolicy [disable=true] --withRoot=true --securityGroup sg-09e5fc379012da5b7

Here, cizhiwu/jupyterlab-env:latest is the image you pushed to Docker Hub, and sg-09e5fc379012da5b7 is your Opcenter instance's security group.

After launching the JupyterLab server from the Docker image, go to the, find its Public IPv4 address. For example, if the address is 100.27.35.229, then open your browser and visit:

http://100.27.35.229:8888

This will open JupyterLab.