LoginSignup
4
4

More than 5 years have passed since last update.

Mac+DockerToolBoxでTensorFlow導入まで(できたきがする)

Last updated at Posted at 2016-06-20

はじめに

この記事はTensorFlowの勉強会に参加するにあたって、先週買ったMacにDocker使ってTensorFlowを導入した時の作業メモです。

Mac使うのは小学校ぶりなので非常に操作が怪しい……のと
DockerはWin8.1にVagrant+Dockerで少し遊んだことがあるのでなんとなく操作の雰囲気はわかるんですがそれ以上は正直良くわからん……
程度の知識レベルで書く作業ログなのであまりアテにはしないでください。

DockerToolBox導入

何故か動かなかった。

TensorFlowをMac & Dockerで使ってみたよ

を参考にしつつ、手順DockerToolboxをさくさくインストール。

で、インストールできたっぽいので
とりあえずHello worldしようとしたら

% docker run hello-world
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.

で、どうもこのエラーはDocker-machine自体が起動していない時に起こるエラーらしい。
ので勝手に作られるdefaultのマシンが起動しているか確認

% docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.11.2

% docker-machine status
Running

起動してるよね?めっちゃRunningって書いてあるよね?
解せぬ(´・ω・`)

というわけで一旦作業ログとしてここで放置。眠い。
またあとで何かしら追記します

【追記】何故かdocker runできた

放置して寝てから数日後。ダメならDockerToolbox再インストールからするかーと諦めながらダメ元でやってみたら何故か動きました。
Dockerさんご機嫌ナナメだったのかな?眠かったのかな?(白目

以下作業ログ

# とりあえずダメ元でやってみる
% docker run hello-world
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.

まあ、動くはずがないのでdocker-machine確認

% docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
default   -        virtualbox   Stopped                 Unknown

# 当然起動してないのでstartする
% docker-machine start
Starting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

need to re-run the docker-machine env command.?
ってなったので調べたところ以下の記事がヒット
Docker Machine をローカル VM で始めるには
要するに、Dockerの環境変数を今のShellに繋がないといけないらしい。
ので、接続

% docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/****/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
[***@****-no-MacBook-Pro] ~
% eval "$(docker-machine env default)"

これでOK。基本的に毎回これをしないといけないらしい。
(.bash_profileとかに書く)

これで無事はろーわーるどできました。

# 起動してるdocker-machineを確認
% docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.11.2

# はろーわーるどぼくはーこっこー♪
% docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
a9d36faac0fe: Pull complete
Digest: sha256:e52be8ffeeb1f374f440893189cd32f44cb166650e7ab185fa7735b7dc48d619
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

TensorFlowのコンテナ入れる

% docker run -d -p 8888:8888 -p 6006:6006 --name tensorflow gcr.io/tensorflow/tensorflow
Unable to find image 'gcr.io/tensorflow/tensorflow:latest' locally
latest: Pulling from tensorflow/tensorflow
759d6771041e: Pull complete
8836b825667b: Pull complete
c2f5e51744e6: Pull complete
a3ed95caeb02: Pull complete
b1a230d2f7d7: Pull complete
f4bd848af23b: Pull complete
9ff2d28f3bea: Pull complete
de3ac9a732b6: Pull complete
ba1ff7fd8338: Pull complete
8b638dd1001b: Pull complete
4c3f9ea22d7e: Pull complete
Digest: sha256:8ae5229583adf18c1e50ac7fbf4c25301aef186eb3cc7c23d85999328a72ac4b
Status: Downloaded newer image for gcr.io/tensorflow/tensorflow:latest
5ed6bb0a371d840f44baa2493491fd0b15c4df2e58731e2629802f9588f54ca0
[minami@Minami-no-MacBook-Pro] ~
% docker ps
CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS              PORTS                                            NAMES
5ed6bb0a371d        gcr.io/tensorflow/tensorflow   "/run_jupyter.sh"   11 minutes ago      Up 11 minutes       0.0.0.0:6006->6006/tcp, 0.0.0.0:8888->8888/tcp   tensorflow

手順どおりでとりあえずできたっぽい。
眠いのでまた明日以降続き……

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