Skip to content

Instantly share code, notes, and snippets.

@ymdysk
Last active June 3, 2016 18:09
Show Gist options
  • Save ymdysk/b13b2fde8715bd2e7206e9b4e22f7240 to your computer and use it in GitHub Desktop.
Save ymdysk/b13b2fde8715bd2e7206e9b4e22f7240 to your computer and use it in GitHub Desktop.

Anaconda を Docker で立ち上げて Jupyter を試す

Pythonで機械学習

Python でデータ分析や機械学習をするために多数のライブラリが使われるが、私は別に環境構築を頑張りたいわけではない。 ありがたいことに、Continuum Analytics というデータ分析企業が、 Anaconda というパッケージにまとめて公開してくださっている。 また近年の開発環境は Docker のイメージで簡単に取得できることが多く、Anaconda でも Docker イメージがあるようなので使ってみる。

Docker pull

Pull自体は簡単。Docker ありがたや。

Docker pull
$ sudo docker pull continuumio/anaconda
Using default tag: latest
latest: Pulling from continuumio/anaconda
a3ed95caeb02: Pull complete
79362e2488a1: Pull complete
045baf0ccb0b: Pull complete
42c3e6650b1b: Pull complete
8142985a9482: Pull complete
Digest: sha256:bf71d93db763521cfbc21b6e2e008447a3dab81cc1060757fd661b0fbc2fee7e
Status: Downloaded newer image for continuumio/anaconda:latest

イメージサイズはそれなりに大きい。

Docker images
$ sudo docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
continuumio/anaconda   latest              d8b2ca6ebc3d        7 weeks ago         1.825 GB

まずは Jupyter を実行

ブラウザで動くインタラクティブでグラフィカルな Python 実行環境、Jupyter (IPython notebook) を使ってみる。 ホームディレクトリに notebooks ディレクトリを作り、そこに実行結果等を保存していくことにする。

Docker run
$ cd ~
$ mkdir notebooks
$ docker run -it -v `pwd`/notebooks:/notebooks -w /notebooks -p 8888:8888 continuumio/anaconda jupyter notebook --ip=172.17.0.2 --no-browser

あとは、ローカルで Docker を動かしているなら、 http://localhost:8888 を見ると Jupyter の画面が開くはず。

リモートで Docker を動かしているなら、SSHのローカルポートフォワーディングで "-L8888:localhost:8888" とかやってリモートホストに接続して、ローカルのブラウザで http://localhost:8888 を開くと使えるはず。

参考情報

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment