概要 †Jupyter lab で Python 以外の言語を利用できる環境を構築する。 目次 †利用できる Jupyter kernel †対象の言語用のカーネルを追加する事で jupyter でPython 以外の言語を利用する事が出来る。 フォルダ構成 †
mkdir container mkdir work docker-compose.yml の作成 †docker-compose.yml version: "3" services: jupyter: build: context: ./container args: MYTOKEN: abcd1234! container_name: my-jupyterlab volumes: - ./work:/home/jovyan/work ports: - 8888:8888 Dockerfileの作成 †ベースとなるイメージは公式のものを使用する container/Dockerfile FROM jupyter/minimal-notebook:lab-4.0.5 # M1 の Mac book の時は --platform=linux/amd64 を指定 #FROM --platform=linux/amd64 jupyter/minimal-notebook:lab-4.0.5 #FROM jupyter/minimal-notebook:lab-3.6.3 #FROM jupyter/scipy-notebook:lab-3.2.3 #ENV DOCKER_DEFAULT_PLATFORM=linux/amd64 USER root RUN apt-get update RUN apt-get install -y build-essential USER jovyan RUN mkdir -p $HOME/.local/share/jupyter/runtime \ && mkdir -p $HOME/.local/share/jupyter/kernels #-------------------------------------------- # Goインストール #-------------------------------------------- USER root #ENV GO_VERSION=1.17.5 ENV GO_VERSION=1.18.10 RUN echo "download go - start" \ && mkdir /tmp/go && cd /tmp/go \ && wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz \ && rm -rf /usr/local/go && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz \ && echo "download go - end" \ && rm -rf /tmp/go #-------------------------------------------- # Go カーネル #-------------------------------------------- USER jovyan ENV GOPATH=$HOME/go RUN mkdir -p $GOPATH ENV PATH=$PATH:/usr/local/go/bin RUN echo "setup go kernel - start" \ && echo "get kernel - start" \ && env GO111MODULE=off go get -d -u github.com/gopherdata/gophernotes \ && cd "$(go env GOPATH)"/src/github.com/gopherdata/gophernotes \ && env GO111MODULE=on go install \ && echo "copy go kernel - start" \ && rm -rf ~/.local/share/jupyter/kernels/gophernotes \ && cp -R kernel ~/.local/share/jupyter/kernels/gophernotes \ && echo "copy go kernel - end" \ && cd ~/.local/share/jupyter/kernels/gophernotes \ && chmod +w ./kernel.json \ && sed "s|gophernotes|$(go env GOPATH)/bin/gophernotes|" < kernel.json.in > kernel.json \ && echo "setup go kernel - end" #-------------------------------------------- # TypeScript カーネル #-------------------------------------------- USER jovyan RUN npm install -g tslab \ && tslab install --python=python3 \ && jupyter kernelspec list #-------------------------------------------- # java インストール #-------------------------------------------- USER jovyan RUN mkdir $HOME/openjdk && cd $HOME/openjdk \ && wget https://download.java.net/java/GA/jdk20.0.2/6e380f22cbe7469fa75fb448bd903d8e/9/GPL/openjdk-20.0.2_linux-x64_bin.tar.gz \ && tar xzfv openjdk-20.0.2_linux-x64_bin.tar.gz \ && rm -rf openjdk-20.0.2_linux-x64_bin.tar.gz ENV PATH=$HOME/openjdk/openjdk-20.0.2/bin:$PATH #-------------------------------------------- # java カーネル #-------------------------------------------- USER jovyan RUN cd /tmp \ && wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip \ && unzip ijava-1.3.0.zip \ && python3 install.py --sys-prefix \ && rm -rf ijava-1.3.0.zip #-------------------------------------------- # Rustインストール #-------------------------------------------- USER root ENV RUST_VERSION=1.72.0 ENV EVCXR_JUPYTER_VERSION=v0.15.1 RUN cd /tmp \ && wget https://static.rust-lang.org/dist/rust-${RUST_VERSION}-x86_64-unknown-linux-gnu.tar.gz \ && tar zxfv rust-${RUST_VERSION}-x86_64-unknown-linux-gnu.tar.gz \ && rust-${RUST_VERSION}-x86_64-unknown-linux-gnu/install.sh \ && wget https://github.com/evcxr/evcxr/releases/download/${EVCXR_JUPYTER_VERSION}/evcxr_jupyter-${EVCXR_JUPYTER_VERSION}-x86_64-unknown-linux-gnu.tar.gz \ && tar xzfv evcxr_jupyter-${EVCXR_JUPYTER_VERSION}-x86_64-unknown-linux-gnu.tar.gz \ && mv evcxr_jupyter-${EVCXR_JUPYTER_VERSION}-x86_64-unknown-linux-gnu/evcxr_jupyter /usr/local/bin/evcxr_jupyter #RUN cargo install evcxr_jupyter USER jovyan RUN evcxr_jupyter --install #-------------------------------------------- # R インストール #-------------------------------------------- USER root RUN apt install -y r-base r-base-dev RUN echo "install.packages('IRkernel')" >/tmp/install.r \ && echo "IRkernel::installspec( user = FALSE, sys_prefix = TRUE )" >>/tmp/install.r \ && R -f /tmp/install.r #-------------------------------------------- # ホームディレクトリ変更&トークン固定 #-------------------------------------------- USER jovyan # docker-compose.yml 側で指定した固定トークン ARG MYTOKEN RUN mkdir -p $HOME/work RUN jupyter lab --generate-config \ && mv $HOME/.jupyter/jupyter_lab_config.py $HOME/.jupyter/jupyter_lab_config.bak \ && cat $HOME/.jupyter/jupyter_lab_config.bak | awk -v workdir=$HOME/work '{ if ($2=="c.ServerApp.notebook_dir") { print; print "c.ServerApp.notebook_dir = \047"workdir"\047"; print "c.ServerApp.root_dir = \047"workdir"\047"; } else { print;} }' | awk -v mytoken=$MYTOKEN '{ if ($2=="c.ServerApp.token") { print; print "c.ServerApp.token = \047"mytoken"\047" } else { print;} }' > $HOME/.jupyter/jupyter_lab_config.py #-------------------------------------------- # ポートバインド設定 #-------------------------------------------- EXPOSE 8888/tcp EXPOSE 8888/udp #-------------------------------------------- # jupyter lab起動 #-------------------------------------------- CMD ["jupyter", "lab"] コンテナ作成/起動 †docker-compose up --build -d Token確認 †トークン固定を行わない場合は以下の通りトークンを確認する docker exec -i my-jupyterlab jupyter lab list Currently running servers: http://e43d493977dc:8888/?token=427aea993fdb768ef4f442d0b1cd600f56cf73f30bf8d316 :: /home/jovyan |