#mynavi(Python覚え書き)
#setlinebreak(on);

* 概要 [#wd12d47f]
#html(<div class="pl20">)
Jupyter lab で Python 以外の言語を利用できる環境を構築する。
尚、当記事では公式の Dockerイメージに Go と Typescript のカーネルを追加するサンプルを記載する。
#html(</div>)

* 目次 [#k8203827]
#contents
- 関連
-- [[Jupyter Notebook]]

* 利用できる Jupyter kernel [#t95b4f5d]
#html(<div class="pl20">)
対象の言語用のカーネルを追加する事で jupyter でPython 以外の言語を利用する事が出来る。
https://github.com/jupyter/jupyter/wiki/Jupyter-kernels
#html(</div>)

* Dockerfileの作成 [#jbf7e9e8]
#html(<div class="pl20">)

ベースとなるイメージは公式のものを使用する
https://jupyter-docker-stacks.readthedocs.io/en/latest/

container/Dockerfile
#mycode2(){{
FROM jupyter/scipy-notebook

USER root

RUN apt-get update
RUN apt-get install -y build-essential

#--------------------------------------------
# Goインストール
#--------------------------------------------
RUN echo "download go - start" \
 && mkdir /tmp/go && cd /tmp/go \
 && wget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz \
 && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.5.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 \
 && mkdir -p ~/.local/share/jupyter/kernels/gophernotes \
 && echo "copy go kernel - start" \
 && cp 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 カーネル
#--------------------------------------------
RUN npm install -g tslab \
 && tslab install --python=python3 \
 && jupyter kernelspec list

#--------------------------------------------
# ポートバインド設定
#--------------------------------------------
EXPOSE 8888/tcp
EXPOSE 8888/udp

#--------------------------------------------
# jupyter lab起動
#--------------------------------------------
RUN mkdir -p $HOME/work && chmod -R 766 $HOME/work
CMD ["jupyter", "lab"]
}}

#html(</div>)

* docker-compose.yml の作成 [#q2a7a9b9]

#html(<div class="pl20">)
docker-compose.yml
#mycode2(){{
version: "3"
services:
    jupyter:
        build:
          context: ./container
        container_name: my-jupyterlab
        volumes:
          - ./work:/home/jovyan/work
        ports:
          - 8888:8888
}}
#html(</div>)

* コンテナ作成/起動 [#b71812e0]
#html(<div class="pl20">)
#myterm2(){{
docker-compose up --build -d
}}
#html(</div>)

* Token確認 [#va74d4de]
#html(<div class="pl20">)
#myterm2(){{
docker exec -i my-jupyterlab jupyter lab list

Currently running servers:
http://e43d493977dc:8888/?token=427aea993fdb768ef4f442d0b1cd600f56cf73f30bf8d316 :: /home/jovyan
}}
#html(</div>)

トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS