基于docker安装tensorflow的完整步骤

2020-06-17 07:04:19易采站长站整理

$ sudo usermod -aG docker $USER

最后重新登录下系统

测试Docker

确保服务启动


$ sudo service docker start

使用HelloWorld测试

测试安装是否成功


docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
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.
(amd64)
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/

若能显示,证明安装成功。

安装Tensorflow

有了Docker,安装Tensorflow基本没有什么难度。

下载镜像


docker pull tensorflow/tensorflow

下载完毕后显示:


Status: Downloaded newer image for tensorflow/tensorflow:latest

创建Tensorflow容器


docker run --name my-tensorflow -it -p 8888:8888 -v ~/tensorflow:/test/data tensorflow/tensorflow

–name:创建的容器名,即my-tensorflow
-it:保留命令行运行
p 8888:8888:将本地的8888端口和http://localhost:8888/映射
-v ~/tensorflow:/test/data:将本地的~/tensorflow挂载到容器内的/test/data下
tensorflow/tensorflow :默认是tensorflow/tensorflow:latest,指定使用的镜像

输入以上命令后,默认容器就被启动了,命令行显示:


[I 15:08:31.949 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 15:08:31.970 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 15:08:31.975 NotebookApp] Serving notebooks from local directory: /notebooks
[I 15:08:31.975 NotebookApp] 0 active kernels