docker インストールとTensorflowコンテナの起動
Dockerのインストール・設定とTensorflowコンテナを起動した時の手順。
Dockerインストール手順はちょくちょく変わっているようなので、最新の情報は公式ドキュメントを参照すること。
公式ドキュメントでのUbuntuへのDockerインストール手順
Get Docker for Ubuntu - Docker Documentation
Dockerインストール
sudo apt-get update # … # Reading package lists... Done sudo apt-get -y install \ linux-image-extra-$(uname -r) \ linux-image-extra-virtual # … # Setting up linux-image-generic (4.4.0.66.70) ... # Setting up linux-image-extra-virtual (4.4.0.66.70) ... curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # [sudo] password for chie8842: # OK sudo apt-key fingerprint 0EBFCD88 # pub 4096R/0EBFCD88 2017-02-22 # Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 <- 公式ドキュメント(https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository)に載っているフィンガープリントと一致しているか確認すること。 uid Docker Release (CE deb) <docker@docker.com> # sub 4096R/F273FCD8 2017-02-22 sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" sudo apt-get update # … # Reading package lists... Done sudo apt-get install docker-ce apt-cache madison docker-ce # docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages sudo docker run hello-world # Unable to find image 'hello-world:latest' locally # latest: Pulling from library/hello-world # 78445dd45222: Pull complete # BDigest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 # 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 ID: # https://cloud.docker.com/ # For more examples and ideas, visit: # https://docs.docker.com/engine/userguide/
インストール後の設定
現在のユーザでDockerを実行できるように権限付与する
sudo groupadd docker # groupadd: group 'docker' already exists sudo usermod -aG docker $USER docker run -it ubuntu bash # docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied. # 公式ドキュメントの通りだと、ここでdocker run に成功するはずだが、 # 上記のように失敗する。OS再起動したらうまくいくようになった。 sudo shutdown -r now docker run -it ubuntu bash # 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 ID: # https://cloud.docker.com/ # For more examples and ideas, visit: # https://docs.docker.com/engine/userguide/
Dockerサービスの起動と自動起動の設定
sudo systemctl enable docker # [sudo] password for chie8842: # Synchronizing state of docker.service with SysV init with /lib/systemd/systemd-sysv-install... # Executing /lib/systemd/systemd-sysv-install enable docker sysv-rc-conf --list |grep docker # docker 0:off 1:off 2:on 3:on 4:on 5:on 6:off # 自動起動がONになっていない場合は、自動起動をONにする。 sudo sysv-rc-conf docker on
Tensorflowコンテナの起動
docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow # 初回はDockerイメージのダウンロードが行われるので時間がかかる # … # Copy/paste this URL into your browser when you connect for the first time, # to login with a token: # http://localhost:8888/?token=******* <-このURLでブラウザを開くと、Jupyter Notebookにアクセスできる。
開いたJupyter Notebookのキャプチャ
デフォルトでGetting StartedやMNistなどのサンプルのノートブックが入っている。