Search code examples
dockerdocker-composedockerfilejupyter-lab

Can't open Jupyter Lab runing on local Docker


I'm creating a course that will require students to run some software called PyStan. It turns out that this is only partially supported on Windows.

Someone gave me an idea to use Docker so that students wouldn't have any issue getting the software they need to do assignments. The end goal is that students can do very little to get Jupyter Lab up and running on their own machines, with as little effort as possible.

I tried writing the following to be run with sudo docker compose up

version: '3'
services:
  ubuntu_anaconda:
    image: continuumio/anaconda3:latest
    container_name: ubuntu_anaconda
    environment:
      - LANG=C.UTF-8
      - JUPYTER_TOKEN=my_secret_token  # Set your desired token here
    ports:
      - "8888:8888"  # Expose Jupyter Lab port
    volumes:
      - ./data:/data  # Add this line if you want to mount a local directory to the container
    command: /bin/bash -c "/opt/conda/bin/conda install -y -c conda-forge pystan && /opt/conda/bin/jupyter lab --ip=0.0.0.0 --port=8888 --allow-root --NotebookApp.token=$${JUPYTER_TOKEN}"

However, when I open up a web browser and navigate to http://localhost:8888/ or http://localhost:8888/?token=my_secret_token it says

The connection was reset

The connection to the server was reset while the page was loading.

  • The site could be temporarily unavailable or too busy. Try again in a few moments.
  • If you are unable to load any pages, check your computer’s network connection.
  • If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the web.

On the other hand, when I navigate to https://127.0.0.1:8888/ it says

Secure Connection Failed

An error occurred during a connection to 127.0.0.1:8888. PR_END_OF_FILE_ERROR

Error code: PR_END_OF_FILE_ERROR

  • The page you are trying to view cannot be shown because the authenticity of the received data could not be verified. Please contact the website owners to inform them of this problem.

Solution

  • Here is docker-compose that works for me, it only requires create directory ./notebooks with permission 777 or to be owner by user id 1000

    version: "3.9"
    
    services:
      jupyter:
        image: jupyter/scipy-notebook
        ports:
          - "8888:8888"
        volumes:
          - ./notebooks:/home/jovyan/
        environment:
          JUPYTER_ENABLE_LAB: "yes"
          JUPYTER_TOKEN: 1234
        command: bash -c "pip install pystan && start-notebook.sh --NotebookApp.token='${JUPYTER_TOKEN}'"