やりたいこと
-
- Windows上でpythonの実行環境(Jupyterlab)を構築する
マシンを汚したくないのでDocker上に構築する
環境
-
- Windows10 Pro : DockerがHyper Vを使用するためProである必要がある。
- Docker Desktop Ver 2.0.0.3
Dockerのインストール
Windows用のDocker Desktopをダウンロードします。ダウンロードが終了したら、実行して指示に従いインストールしてください。
ダウンロード元:Docker Desktop
Docker IDを取得し、設定しておきます。
Jupyterlabコンテナの準備
Dockerリポジトリからjupyterがインストールされているイメージをpull(ダウンロード)します。Windows PowerShell を起動し、次のコマンドを実行してください。
docker pull jupyter/scipy-notebook

FROM jupyter/scipy-notebook
RUN pip install --upgrade pip
RUN pip install jupyterlab
RUN jupyter serverextension enable --py jupyterlab
Windows PowerShellに戻り、カレントフォルダを先ほど作成したdockerfileがあるフォルダに移動します。
移動したら、次のコマンドを実行し、dockerfileをビルドします。
docker build -t jupyterlab:latest ./
ビルドが終了したら、コンテナを作成します。次のコマンドを実行してください。
docker run -p 8888:8888 --name jupyterlab -v ${pwd}:/home/jovyan/work jupyterlab:latest start.sh jupyter lab
すると画面に
Executing the command: jupyter lab
[I 14:45:57.953 LabApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[I 14:45:58.870 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.7/site-packages/jupyterlab
[I 14:45:58.870 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 14:45:58.872 LabApp] Serving notebooks from local directory: /home/jovyan
[I 14:45:58.873 LabApp] The Jupyter Notebook is running at:
[I 14:45:58.873 LabApp] http://(57d0e8f9ed9f or 127.0.0.1):8888/?token=d7ccc6e3d36f48afdc64681c83021d998f10c48e24f39e72
[I 14:45:58.873 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 14:45:58.877 LabApp]
To access the notebook, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
Or copy and paste one of these URLs:
http://(57d0e8f9ed9f or 127.0.0.1):8888/?token=d7ccc6e3d36f48afdc64681c83021d998f10c48e24f39e73
上記のように表示されます。指示に従い、ブラウザのURLに入れてるとJupyterlabが起動します。
http://127.0.0.1:8888/?token=d7ccc6e3d36f48afdc64681c83021d998f10c48e24f39e73
起動と停止
コンテナの起動と停止にはCONTAINER IDを指定します。CONTAINER IDを確認するには下記コマンドを実行します。構築済みにコンテナすべてが表示されます。起動中のコンテナのみを表示させたい場合は、”-a”は不要です。
docker ps -a
コンテナの起動と停止は以下のコマンドを実行してください。
docker start -a <container id>
docker stop <container id>
※マシンを再起動するとコンテナを起動できない場合があり、
その場合は docker を Restart してください。