深入理解tensorflow我爱编程

Docker Support Tensorflow start

2018-08-07  本文已影响86人  it_zzy

Docker Support Tensorflow start


Tensoflow 容器启动

启动Tensorflow容器还是比较简单的,根据docker hub提供的方法进行容器启动即可

1.搜索镜像
root@es2:~# docker search tensorflow
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tensorflow/tensorflow             Official docker images for deep learning f...   1001
jupyter/tensorflow-notebook       Jupyter Notebook Scientific Python Stack w...   74
xblaster/tensorflow-jupyter       Dockerized Jupyter with tensorflow              50                   [OK]
romilly/rpi-docker-tensorflow     Tensorflow and Jupyter running in docker c...   19
floydhub/tensorflow               tensorflow                                      12                   [OK]
bitnami/tensorflow-serving        Bitnami Docker Image for TensorFlow Serving     11                   [OK]
tensorflow/serving                Official images for TensorFlow Serving (ht...   8

2.下载镜像
root@es2:~# docker pull tensorflow/tensorflow
Using default tag: latest
latest: Pulling from tensorflow/tensorflow
b234f539f7a1: Extracting [===========================>                       ]  23.4 MB/43.12 MB
55172d420b43: Download complete
5ba5bbeb6b91: Download complete
43ae2841ad7a: Download complete
f6c9c6de4190: Download complete
5624105f79a2: Downloading [======>                                            ] 17.12 MB/142.4 MB
1cbdffd12405: Download complete

3.启动容器
docker run -d --name tensorflow_test -p 18888:8888 tensorflow/tensorflow
参数解析:
-d 后台运行
--name 给容器起个名字
-p 映射到本地的端口(本地端口:容器端口)

登录jupyter

1.找到登录token
jupyter登录需要传入token,获取方式如下:

docker ps
root@es2:~# docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                               NAMES
17d804ae12cc        tensorflow/tensorflow    "/run_jupyter.sh -..."   58 seconds ago      Up 58 seconds       6006/tcp, 0.0.0.0:18888->8888/tcp   tensorflow_test
d939ac70635a        google/cadvisor:latest   "/usr/bin/cadvisor..."   5 days ago          Up 5 days           0.0.0.0:8080->8080/tcp              cadvisor
b9f4b7b1295c        registry:2               "/entrypoint.sh /e..."   6 days ago          Up 6 days           0.0.0.0:5000->5000/tcp              registry2

找到要启动容器的ID
docker logs 17d804ae12cc
root@es2:~# docker logs 17d804ae12cc
[I 08:13:35.956 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 08:13:35.972 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 08:13:35.980 NotebookApp] Serving notebooks from local directory: /notebooks
[I 08:13:35.980 NotebookApp] 0 active kernels
[I 08:13:35.980 NotebookApp] The Jupyter Notebook is running at:
[I 08:13:35.980 NotebookApp] http://17d804ae12cc:8888/?token=4e392a15850c82958dd68a7e2eca205ae112740ce2ceb437
[I 08:13:35.980 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 08:13:35.980 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://17d804ae12cc:8888/?token=4e392a15850c82958dd68a7e2eca205ae112740ce2ceb437&token=4e392a15850c82958dd68a7e2eca205ae112740ce2ceb437

找到这条日志后,然后替换ip与端口
http://宿主机:映射端口/?token=4e392a15850c82958dd68a7e2eca205ae112740ce2ceb437
Jupyter.png

容器安装Python3 Anaconda3

如果需要环境中支持Anaconda需要手动去容器安装

1.登录容器
docker exec -it 17d804ae12cc  bash
root@es2:~# docker exec -it 17d804ae12cc  bash
root@17d804ae12cc:/notebooks#

2.更新apt-get安装wget
apt-get update
root@17d804ae12cc:/notebooks# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
...
apt-get install wget
root@17d804ae12cc:/notebooks# apt-get install wget
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
wget
...

3.下载Anaconda3
root@17d804ae12cc:/notebooks# wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
--2018-08-07 08:35:17--  https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.17.111.77, 104.17.110.77, 104.17.107.77, ...
Connecting to repo.anaconda.com (repo.anaconda.com)|104.17.111.77|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 651745206 (622M) [application/x-sh]
Saving to: 'Anaconda3-5.2.0-Linux-x86_64.sh'

Anaconda3-5.2.0-Linux-x86_64.sh            15%[===========>
...
Saving to: 'Anaconda3-5.2.0-Linux-x86_64.sh'

Anaconda3-5.2.0-Linux-x86_64.sh           100%[==================================================================================>] 621.55M  12.3MB/s    in 49s

2018-08-07 08:36:07 (12.6 MB/s) - 'Anaconda3-5.2.0-Linux-x86_64.sh' saved [651745206/651745206]

4.运行安装
bash Anaconda3-5.2.0-Linux-x86_64.sh
root@17d804ae12cc:/notebooks# bash Anaconda3-5.2.0-Linux-x86_64.sh

Welcome to Anaconda3 5.2.0

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

5.jupyter notebook加载pytho3内核
ipython kernel install --name python3
root@17d804ae12cc:/notebooks# ipython kernel install --name python3
Installed kernelspec python3 in /usr/local/share/jupyter/kernels/python3

保存镜像

安装了Anaconda3的容器,想在别的机器上使用,而不想再次安装的话,可以将已经安装的容器保存成镜像

1.创建镜像
docker commit  -a "test" -m "install Anaconda3-5.2.0"  17d804ae12cc tensorflow:1.0.0
如此就把容器保存成了加载中的镜像,其中TAG为了区分同名镜像的不同版本
语法 docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
说明:
 -a:提交的镜像作者
 -c:使用Dockerfile指令来创建镜像
 -m:提交时的说明文字
 -p:在commit时,将容器暂停

root@es2:~# docker commit  -a "test" -m "install Anaconda3-5.2.0"  17d804ae12cc tensorflow:1.0.0
sha256:8ff9c17845442d36f0fe43fbc65fa6cda6aef7a7bd5d69455eaf232b9fc6ceaf

- 查看镜像
root@es2:~# docker images
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
tensorflow                                 1.0.0               8ff9c1784544        2 minutes ago       5.22 GB
es2:5000/itzzy/eureka-server-1.0.0         latest              3c8d61cfde11        10 days ago         723 MB
itmuch/eureka-server-1.0.0                 latest              3c8d61cfde11        10 days ago         723 MB
itzzy/eureka-server-1.0.0                  latest              3c8d61cfde11        10 days ago         723 MB
localhost:5000/itzzy/eureka-server-1.0.0   latest              3c8d61cfde11        10 days ago         723 MB
ubuntu                                     16.04               7aa3602ab41e        11 days ago         115 MB
tensorflow/tensorflow                      latest              caab7ec02690        3 weeks ago         1.25 GB

2.保存镜像
docker save -o tensorflow_Anaconda3-5.2.0.tar  tensorflow:1.0.0
可以看到生成了tar文件
-rw-------  1 root root 5340353536 Aug  7 17:19 tensorflow_Anaconda3-5.2.0.tar

3.其他主机加载镜像
只需要把你保存的镜像传过去load 一下就好了
docker load -i tensorflow_Anaconda3-5.2.0.tar
上一篇下一篇

猜你喜欢

热点阅读