DEV Community

Cover image for How to run JupyterLab on Docker
Juan Belieni
Juan Belieni

Posted on

How to run JupyterLab on Docker

Jupyter and JupyterLab are great tools for data science. Sometimes it is more convenient to simply run them with Docker as containers, which can be easily stopped and deleted after use.

Selecting the image

Jupyter has a lot of images at Docker Hub. Fortunately, Jupyter documentation covers this topic very well. Here, I will use the jupyter/datascience-notebook image, which "includes libraries for data analysis from the Julia, Python, and R communities".

Running with Docker Compose

I particularly like to create a Docker Compose file for each service I use with Docker, because it is better to manage all the necessary options.

First, you have to map the port of the service to a port at your computer. I recommend using the same default port as Jupyter.

jupyter:
  image: jupyter/datascience-notebook:latest
  container_name: jupyter
  ports:
    - 8888:8888
Enter fullscreen mode Exit fullscreen mode

Now, it will just be necessary to define two environment variables, JUPYTER_ENABLE_LAB and JUPYTER_TOKEN. Here, you can define the most convenient token for you.

jupyter:
  image: jupyter/datascience-notebook:latest
  container_name: jupyter
  ports:
    - 8888:8888
  environment:
    JUPYTER_ENABLE_LAB: "yes"
    JUPYTER_TOKEN: "docker"
Enter fullscreen mode Exit fullscreen mode

Finally, just run the Docker Compose command to start your container.

docker-compose up
Enter fullscreen mode Exit fullscreen mode

Running from Docker CLI

If you prefer to run this container from Docker CLI, just copy and paste this command.

docker run -p 8888:8888 \
           -e JUPYTER_ENABLE_LAB=yes \
           -e JUPYTER_TOKEN=docker \
           --name jupyter \
           -d jupyter/datascience-notebook:latest
Enter fullscreen mode Exit fullscreen mode

Accessing JupyterLab

At your browser, just enter http://localhost:8888 and provide the token defined by you.

Discussion (0)