- How to Run Jupyter Notebook in a Docker Container
- 1. Choose a Jupyter Notebook template
- 2. Start the container
- 3. Open localhost
- Saved searches
- Use saved searches to filter your results more quickly
- License
- jupyter/docker-stacks
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- stefanproell/jupyter-notebook-docker-compose
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
How to Run Jupyter Notebook in a Docker Container
Running a Jupyter Notebook in Docker is simpler than expected. No need to install anything locally (other than Docker, of course).
Assuming we have Docker installed, let’s decide which Jupyter Notebook template we want to use.
1. Choose a Jupyter Notebook template
These are the available notebook templates in the Jupyter Docker Stack.
These are ready-to-run Docker images containing Jupyter applications.
- base-notebook: small baseline environment
- datascience-notebook: environment with common data science packages
- minimal-notebook: minimalistic environment
- pyspark-notebook: environment with PySpark
- all-spark-notebook: environment with Scala, R, etc.
- r-notebook: environment with R
- scipy-notebook: environment with SciPy
- tensorflow-notebook: environment with TensorFlow
Let’s say we want to use the scipy-notebook .
If you’re running Docker without root , prepend all the commands with sudo .
2. Start the container
The following command is all we need to get a container up and running.
docker run -p 8888:8888 jupyter/scipy-notebook
However, ideally, we’ll want to edit a Jupyter Notebook that already exists, or at least save a notebook to our local machine.
This requires us to mount a directory on the host inside the container. This will expose our host directory inside the container, which can then read from and write to this directory.
We can achieve this with the -v argument.
docker run -v $(pwd):/home/jovyan/work -p 8888:8888 jupyter/scipy-notebook
The $(pwd) will refer to the directory in which this command is run, so anything in the current directory will be accessible inside the container. We can also specify an absolute or relative path. Either way, we’ll want our existing notebooks to reside in that location.
The /home/jovyan/work is the starting workspace inside the Docker image.
jovyan is a play on the word jovian , which means “like Jupiter”, and refers to members of the Jupyter community (source).
3. Open localhost
After running docker run , we should see logs that look something like this.
[I 01:50:11.178 NotebookApp] Serving notebooks from local directory: /home/jovyan [I 01:50:11.178 NotebookApp] Jupyter Notebook 6.4.5 is running at: [I 01:50:11.178 NotebookApp] http://64fdfb2c87f1:8888/?token=d4b65f7b870928aca803efc025b914725adc4160b70b8c44 [I 01:50:11.178 NotebookApp] or http://127.0.0.1:8888/?token=d4b65f7b870928aca803efc025b914725adc4160b70b8c44 [I 01:50:11.178 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 01:50:11.191 NotebookApp] To access the notebook, open this file in a browser: file:///home/jovyan/.local/share/jupyter/runtime/nbserver-8-open.html Or copy and paste one of these URLs: http://64fdfb2c87f1:8888/?token=d4b65f7b870928aca803efc025b914725adc4160b70b8c44 or http://127.0.0.1:8888/?token=d4b65f7b870928aca803efc025b914725adc4160b70b8c44
This log contains the generated localhost URL and a token. We can easily open up the 127.0.0.1:8888 URL with the token parameter in our browser to start using the notebook.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Ready-to-run Docker images containing Jupyter applications
License
jupyter/docker-stacks
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
* Some fixes for Jupyter Notebook 7 * Fix jupyter nbextension * Remove explicit port setting
Git stats
Files
Failed to load latest commit information.
README.md
Jupyter Docker Stacks are a set of ready-to-run Docker images containing Jupyter applications and interactive computing tools. You can use a stack image to do any of the following (and more):
- Start a personal Jupyter Server with the JupyterLab frontend (default)
- Run JupyterLab for a team using JupyterHub
- Start a personal Jupyter Notebook server in a local Docker container
- Write your own project Dockerfile
You can try a relatively recent build of the jupyter/base-notebook image on mybinder.org by simply clicking the preceding link. Otherwise, the examples below may help you get started if you have Docker installed, know which Docker image you want to use and want to launch a single Jupyter Server in a container.
The User Guide on ReadTheDocs describes additional uses and features in detail.
This command pulls the jupyter/scipy-notebook image tagged 2023-06-01 from Docker Hub if it is not already present on the local host. It then starts a container running a Jupyter Server and exposes the container’s internal port 8888 to port 10000 of the host machine:
docker run -p 10000:8888 jupyter/scipy-notebook:2023-06-01
You can modify the port on which the container’s port is exposed by changing the value of the -p option to -p 8888:8888 .
Visiting http://:10000/?token= in a browser loads JupyterLab, where:
- hostname is the name of the computer running Docker
- token is the secret token printed in the console.
The container remains intact for restart after the Jupyter Server exits.
This command pulls the jupyter/datascience-notebook image tagged 2023-06-01 from Docker Hub if it is not already present on the local host. It then starts an ephemeral container running a Jupyter Server and exposes the server on host port 10000.
docker run -it --rm -p 10000:8888 -v "$ ":/home/jovyan/work jupyter/datascience-notebook:2023-06-01
The use of the -v flag in the command mounts the current working directory on the host ( $ in the example command) as /home/jovyan/work in the container. The server logs appear in the terminal.
Visiting http://:10000/?token= in a browser loads JupyterLab.
Due to the usage of the flag —rm Docker automatically cleans up the container and removes the file system when the container exits, but any changes made to the ~/work directory and its files in the container will remain intact on the host. The -it flag allocates pseudo-TTY.
Please see the Contributor Guide on ReadTheDocs for information about how to contribute recipes, features, tests, and community maintained stacks.
We value all positive contributions to the Docker stacks project, from bug reports to pull requests to help with answering questions. We’d also like to invite members of the community to help with two maintainer activities:
- Issue triaging: Reading and providing a first response to issues, labeling issues appropriately, redirecting cross-project questions to Jupyter Discourse
- Pull request reviews: Reading proposed documentation and code changes, working with the submitter to improve the contribution, deciding if the contribution should take another form (e.g., a recipe instead of a permanent change to the images)
Anyone in the community can jump in and help with these activities anytime. We will happily grant additional permissions (e.g., the ability to merge PRs) to anyone who shows an ongoing interest in working on the project.
Jupyter Notebook Deprecation Notice
Following Jupyter Notebook notice, JupyterLab is now the default for all the Jupyter Docker stack images. It is still possible to switch back to Jupyter Notebook (or to launch a different startup command). You can achieve this by passing the environment variable DOCKER_STACKS_JUPYTER_CMD=notebook (or any other valid jupyter subcommand) at container startup; more information is available in the documentation.
According to the Jupyter Notebook project status and its compatibility with JupyterLab, these Docker images may remove the classic Jupyter Notebook interface altogether in favor of another classic-like UI built atop JupyterLab.
This change is tracked in the issue #1217; please check its content for more information.
- jupyter/repo2docker — Turn git repositories into Jupyter-enabled Docker Images
- openshift/source-to-image — A tool for building artifacts from source and injecting them into docker images
- jupyter-on-openshift/jupyter-notebooks — OpenShift compatible S2I builder for basic notebook images
- We publish containers for both x86_64 and aarch64 platforms
- Single-platform images have either aarch64- or x86_64- tag prefixes, for example, jupyter/base-notebook:aarch64-python-3.10.5
- Starting from 2022-09-21 , we create multi-platform images (except tensorflow-notebook )
- Starting from 2023-06-01 , we create multi-platform tensorflow-notebook image as well
This project only builds one set of images at a time. If you want to use older Ubuntu and/or python version, you can use following images:
Build Date | Ubuntu | Python | Tag |
---|---|---|---|
2022-10-09 | 20.04 | 3.7 | 1aac87eb7fa5 |
2022-10-09 | 20.04 | 3.8 | a374cab4fcb6 |
2022-10-09 | 20.04 | 3.9 | 5ae537728c69 |
2022-10-09 | 20.04 | 3.10 | f3079808ca8c |
2022-10-09 | 22.04 | 3.7 | b86753318aa1 |
2022-10-09 | 22.04 | 3.8 | 7285848c0a11 |
2022-10-09 | 22.04 | 3.9 | ed2908bbb62e |
2023-05-30 | 22.04 | 3.10 | 4d70cf8da953 |
weekly build | 22.04 | 3.11 | latest |
About
Ready-to-run Docker images containing Jupyter applications
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A docker-compose file for launching Jupyter Notebooks in a container.
stefanproell/jupyter-notebook-docker-compose
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Jupyter with Docker Compose
This repository contains a simple docker-compose definition for launching the popular Jupyter Data Science Notebook. You can define a password with the script generate_token.py -p S-E-C-R-E-T and generate SSL certificates as described below.
- docker-compose up mounts the directory and starts the container
- docker-compose down destroys the container
The compose file: docker-compose.yml
version: '3' services: datascience-notebook: image: jupyter/datascience-notebook volumes: - $ :/home/jovyan/work - $ :/home/jovyan/work/datasets - $ :/home/jovyan/work/modules - $ :/etc/ssl/notebook ports: - $ :8888 container_name: jupyter_notebook command: "start-notebook.sh \ --NotebookApp.password=$ \ --NotebookApp.certfile=/etc/ssl/notebook/jupyter.pem"
Example with a custom user
version: '2' services: datascience-notebook: image: jupyter/base-notebook:latest volumes: - /tmp/jupyter_test_dir:/home/docker_worker/work ports: - 8891:8888 command: "start-notebook.sh" user: root environment: NB_USER: docker_worker NB_UID: 1008 NB_GID: 1011 CHOWN_HOME: 'yes' CHOWN_HOME_OPTS: -R
# Define a local data directory # Set permissions for the container: # sudo chown -R 1000 $ LOCAL_WORKING_DIR=/data/jupyter/notebooks # Generate an access token like this # import IPython as IPython # hash = IPython.lib.passwd("S-E-C-R-E-T") # print(hash) # You can use the script generate_token.py ACCESS_TOKEN=sha1:d4c78fe19cb5:0c8f830971d52da9d74b9985a8b87a2b80fc6e6a # Host port PORT=8888 # Provide data sets LOCAL_DATASETS=/data/jupyter/datasets # Provide local modules LOCAL_MODULES=/home/git/python_modules # SSL # Generate cert like this: # openssl req -x509 -nodes -newkey rsa:2048 -keyout jupyter.pem -out jupyter.pem # Copy the jupyter.pem file into the location below. LOCAL_SSL_CERTS=/opt/ssl-certs/jupyter
Make sure to have the latest versions installed. You can use the Notebook Browser interface.