LoginSignup
28
36

More than 5 years have passed since last update.

Jupyter LabをDockerで環境構築する

Last updated at Posted at 2019-03-08

概要

Jupyter LabのDockerでの環境構築方法

関連記事

環境

  • jupyterlab 0.35.4

Dockerイメージの作成

Dockerイメージをpull

$ sudo docker pull jupyter/datascience-notebook

Dockerfileを作成

FROM jupyter/datascience-notebook

RUN pip install --upgrade pip
RUN pip install jupyterlab
RUN jupyter serverextension enable --py jupyterlab

build

$ sudo docker build -t jupyterlab:latest ./

jupyterlabのパスワードを設定

以下のコマンドで、jupyterlabにブラウザでアクセスする際のパスワードを設定する。

$ sudo docker run --rm -it \
  jupyter/datascience-notebook /bin/bash -c \
  "python -c 'from notebook.auth import passwd;print(passwd())'"

# パスワードを入力
Enter password:
Verify password:
# ハッシュ化されたパスワード
sha1:xxxxxxxxxxxxxxxxxxxxxxxx

jupyter-notebook4.3からセキュリティが厳しくなったらしい
https://jupyter-notebook.readthedocs.io/en/latest/security.html#server-security

ハッシュ化されたパスワードを付与してjupyterlabを起動する

--NotebookApp.passwordオプションに、ハッシュ化されたパスワードをセットする。

sudo docker run  \
    --rm \
    -e TZ=Asia/Tokyo \
    -p 8888:8888 \
    --name jupyterlab \
    -v $(pwd)/code:/code \
    jupyterlab:latest \
    start.sh jupyter lab --NotebookApp.password="sha1:xxxxxxxxxxxxxxxxxxxxxxxx"

ブラウザでアクセス

http://localhost:8888
ブラウザでアクセスし、先程設定したパスワードを入力する。

Notebookでpython3を実行してみる

Screen Shot 2019-03-08 at 18.04.54.png

pythonを実行

Screen Shot 2019-03-08 at 18.05.25.png

pythonファイルを実行する場合

pythonファイルを実行する場合は、%runを使う。

%run -i {ファイル名}

また、cdとかlsとかいったシェルコマンドも使える。

Screen Shot 2019-03-08 at 18.16.28.png

参考

28
36
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
36