[PYTHON] Easy installation and launch of Jupyter Notebook using Docker (also supports nbextensions and Scala)

As the title says, it is a work log for easily installing and using Jupyter Notebook using Docker. Make Scala available on Jupyter Notebook as well.

It is assumed that docker is already installed.

Prepare the following Dockerfile. Write down all the Python packages you might use.

Dockerfile


FROM centos:7

RUN yum install -y python3 java-11-openjdk
RUN pip3 install jupyter jupyter-contrib-nbextensions jupyter_nbextensions_configurator numpy pandas matplotlib scikit-learn mlxtend boto3

RUN jupyter contrib nbextension install

# Jupyter-Scala installation
WORKDIR /install
ENV SCALA_VERSION=2.13.1
ENV ALMOND_VERSION=0.8.2
RUN curl -Lo coursier https://git.io/coursier-cli
RUN chmod +x coursier
RUN ./coursier bootstrap -r jitpack -i user -I user:sh.almond:scala-kernel-api_$SCALA_VERSION:$ALMOND_VERSION sh.almond:scala-kernel_$SCALA_VERSION:$ALMOND_VERSION -o almond
RUN ./almond --install

WORKDIR /work

CMD jupyter notebook --ip='*' --no-browser --allow-root --NotebookApp.token=''

The Python packages jupyter-contrib-nbextensions, jupyter_nbextensions_configurator, and the subsequent jupyter contrib nbextension install are for using nbextensions.

See the official page below for installing Jupyter-Scala. Installation ยท almond

The jupyter option --allow-root is an option required to run Jupyter with root privileges. It is necessary because it has root privileges in Docker.

--ip ='*' is a setting that allows you to access Jupyter from anywhere. --NotebookApp.token ='' is a setting to skip token input when accessing Jupyter with a browser. I'm running this on Linux running in VirtualBox inside my PC, so I've set these for convenience, but this is a setting that can be freely accessed from the outside and is usually not recommended think.

Create an image with the following command in the directory containing this Dockerfile.

$ docker build -t myjupyter .

After moving to the directory where you want to work with Jupyter, start Jupyter with the following command.

$ docker run -it --rm -p 8888:8888 -v $HOME/.aws:/root/.aws -v $(pwd):/work myjupyter

I added -v $ HOME / .aws: /root/.aws because I wanted to use boto3 to access the AWS API.

After starting Jupyter, access port 8888 with a browser.

With ordinary Docker, files created with Jupyter will be owned by root, so rootless Docker seems to be better.

Recommended Posts

Easy installation and launch of Jupyter Notebook using Docker (also supports nbextensions and Scala)
The story of launching python2.x jupyter notebook using docker (crushed on Saturday and Sunday)
Installation and easy usage of pytest
Try using Jupyter Notebook of Azure Machine Learning
Easily prepare a Jupyter Notebook environment with Docker (Tensorflow and Graphviz are also available)
Aim for easy installation of OpenCv and Cuda using JetPack (NVIDIA SDK Manager) from Nvidia
Easily launch jupyter notebook on AWS and access locally
Installation of Docker on Raspberry Pi and L Chika
jupyter and pandas installation