LoginSignup
7
2

More than 3 years have passed since last update.

サーバー上でdocker-composeを実行し、起動したDocker上のjupyter notebookをローカルのブラウザで表示する方法

Last updated at Posted at 2019-09-16

docker-composeの実行

(サーバー上)

以下のように、portsを指定して、docker-composeを用意。

docker-compose.yml
version: "2.3"
services:
  jupyter_module:
    build:
      context: .
    image: jupyter
    command: /bin/bash
    ports:
      - 8888:8888
    runtime: nvidia

buildした後に、以下のようにrunする。ただし、普通にrunするとうまくいかないので、一工夫する。

docker/compose/issues/1259 より。--service-ports をつけると良いということ。

$ docker-compose run --service-ports jupyter_module

または、--service-ports を付けなくても、-p のオプションでもできる。

$ docker-compose run -p 8888:8888 jupyter_module

jupyterの用意と実行

(サーバー上)

必要なportを開く。

$ pip install jupyter jupyterlab
$ jupyter notebook --port 8888 --ip=0.0.0.0 --allow-root

サーバーとの接続とjupyterへのアクセス

(ローカル)

ssh ポートフォワーディングでサーバーと繋ぐ。

$ ssh -NfL localhost:8888:localhost:8888 (ssh config name)

以下にアクセスする。jupyter のIDを聞かれたら、入力すればOK。

http://localhost:8888

tokenがinvalidになる場合

既に他のプロセスで使用されているportを使ってnotebookを起動しようとしている可能性があります。
他のポートで確かめてみましょう。sudo netstat -tanpを使えば使われているポート番号を確認できます。

7
2
0

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
7
2