LoginSignup
3
6

More than 5 years have passed since last update.

TensorFlow環境をWindows10 + Vagrant + VirtualBox + Ubuntu + Dockerで構築して触ってみる

Last updated at Posted at 2018-06-24

概要

TensorFlowを勉強するために環境を構築した時の記録。

環境はタイトルにある通り、

  • Windows10 Home 64bit

  • Vagrant

  • VirtualBox

  • Ubuntu 16.04 LTS 64bit

  • Docker

  • TensorFlow CPU Only

Vagrant で Ubuntu 起動

とりあえず Vagrant で Ubuntu の環境を起動しようとしたものの、エラー(404 Not Found)が発生した。

ググったらバージョンアップしたらいいかも。とのことだったので最新バージョンにアップデート。

Version: 1.9.1 -> 2.1.1

vagrant init --minimal bento/ubuntu-16.04 # ここでもエラー。pluginをrepairしろとのこと
vagrant plugin repair
vagrant init --minimal bento/ubuntu-16.04

これでやっと起動できた。と思ったけどまたしてもエラー発生。

PS C:\vm\vagrant\ubuntuDocker> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-16.04' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "66915115-43d7-470a-b287-f3e34bb5ed42", "--type", "headless"]

Stderr: VBoxManage.exe: error: The virtual machine 'ubuntuDocker_default_1529807116548_10076' has terminated unexpectedly during startup with exit code 1 (0x1).  More details may be available in 'C:\Users\husky\VirtualBox VMs\ubuntuDocker_default_1529807116548_10076\Logs\VBoxHardening.log'
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component MachineWrap, interface IMachine

ググったら、VirtualBox のバージョンアップが必要らしい。

Version: 5.1.10 r112026 -> 5.2.12 r122591

これでやっと起動した。

Vagrant 起動まとめ

vagrant init --minimal bento/ubuntu-16.04
vagrant up
vagrant halt
vagrant plugin install vagrant-vbguest

Vagrant ファイル編集

Vagrant.configure("2") do |config|
    config.vm.box = "bento/ubuntu-16.04"
    config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
    config.vm.network "private_network", type: "dhcp"
    config.vm.provider "virtualbox" do |v|
        v.name = "ubuntuDocker"
        v.cpus = 1
        v.memory = 2048
    end
end
vagrant up
vagrant ssh
mount | grep vagrant

これで、/vagrant に ホストのフォルダが mount された状態で起動。

Docker CE のインストール

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
sudo docker run hello-world

TensorFlow の Docker コンテナ起動

TensorFlow はオフィシャルの DockerHub がある。

tensorflow/tensorflow

CPU を使用するものと、GPU を使うものがあるらしい。

# CPU Only
sudo docker run -it -p 8888:8888 tensorflow/tensorflow

# GPU
sudo nvidia-docker run -it -p 8888:8888 tensorflow/tensorflow:latest-gpu

この PC には GPU(nvidia) が乗っているので、GPUでコンテナを起動。と思ったけど、専用の Docker、nvidia-docker をインストールする必要があるらしく面倒なので CPU only で起動。

sudo docker run --name tensorflow -dit -p 8888:8888 -p 6006:6006 tensorflow/tensorflow

TensorFlow にアクセス

まずは URL を確認。

sudo docker logs tensorflow

to login with a token: の後に表示された URL にアクセス。

URL に含まれる localhost 部は、VirtualBox のIPアドレスに読み替えが必要。

Tensorboard にアクセス

Jupter の Home 画面から New -> Terminal でターミナルを開き下記コマンドを実行。

http://172.28.128.3:8888/terminals/1

その後、ブラウザでポート番号 6006 にアクセスすると Tensorboard が表示できる。

3
6
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
3
6