30
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.
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".
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
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"
Finally, just run the Docker Compose command to start your container.
docker-compose up
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
At your browser, just enter http://localhost:8888
and provide the token defined by you.
30