docker安裝 Tensorflow遇到問題i/o timeout.
docker: Error response from daemon: Get https://gcr.io/v1/_ping: dial tcp 64.233.188.82:443: i/o timeout.
Tensorflow 是Google的一個開源機器學習框架,中國大陸的用戶在使用的時候往往需要爬過GFW牆,借助VPN。
依照Tensorflow的官方文檔 在docker中安裝Tensorflow的時候,國內的用戶通常會報錯,有的借助VPN可以解決,而有的不行。
(1)在docker成功安裝完后,在終端命令行輸入:
sudo docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow
(2)報錯如下:
Unable to find image 'gcr.io/tensorflow/tensorflow:latest' locally docker: Error response from daemon: Get https://gcr.io/v1/_ping: dial tcp 64.233.188.82:443: i/o timeout. See 'docker run --help'.
主要原因還是因為GFW,在Github上有人提出過引起這個問題的原因,tensorflow/issues/1273,點擊此鏈接。
(3)關於這個,問題,我覺得最簡單的辦法是更換鏡像的pull鏡像庫。也就是說,不是從Tensorflow給出的庫(Google Cloud Platform)進行pull,而是用docker的庫(docker hub)。
docker hub 中的tensorflow鏡像介紹:
因此,在終端輸入如下命令:
sudo docker run -it -p 8888:8888 tensorflow/tensorflow
只要你的docker是安裝成功,能夠pull鏡像,那么基本會成功安裝Tensorflow。我的運行輸出如下:
Unable to find image 'tensorflow/tensorflow:latest' locally latest: Pulling from tensorflow/tensorflow 862a3e9af0ae: Pull complete 6498e51874bf: Pull complete 159ebdd1959b: Pull complete 0fdbedd3771a: Pull complete 7a1f7116d1e3: Pull complete f22ce26e7804: Pull complete 80e54362977d: Pull complete 6bf17916f3f1: Pull complete cbb2cc9179cb: Pull complete 4f976cd18afd: Pull complete 31ba02bae790: Pull complete e26c94fb0976: Pull complete Digest: sha256:feedf027da0d525300dc73e433b4ade2147c6a408756cdd9846fd37b40929f8a Status: Downloaded newer image for tensorflow/tensorflow:latest [I 03:19:59.901 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret [W 03:19:59.981 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended. [I 03:20:00.015 NotebookApp] Serving notebooks from local directory: /notebooks [I 03:20:00.015 NotebookApp] 0 active kernels [I 03:20:00.015 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=93a4eec743c0601c77e6b3f88386da5efab335f49d6a476e [I 03:20:00.015 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 03:20:00.016 NotebookApp] Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://localhost:8888/?token=93a4eec743c0601c77e6b3f88386da5efab335f49d6a476e [I 03:25:55.708 NotebookApp] 302 GET /?token=93a4eec743c0601c77e6b3f88386da5efab335f49d6a476e (172.17.0.1) 0.45ms
因為這個鏡像比較大,所以會需要一定的時間pull,耐心等待就好。
(4)打開一個新的命令終端進行測試是否安裝成功:
首先,查看docker中有哪些容器/鏡像存在
sudo docker ps -a
得到如下格式的輸出:
注意到,第一個容器即是我們安裝的tensorflow的鏡像在運行的容器,其ID是53f212117a94
接着,進入容器:
替換我的這個53f212117a94
為你的,其他命令不變
sudo docker exec -i -t 53f212117a94 /bin/bash
- 1
得到輸入如下:
mingchen@mingchen-HP:~$ sudo docker exec -i -t 53f212117a94 /bin/bash root@53f212117a94:/notebooks#
看看python版本:
root@53f212117a94:/notebooks# python Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information.
輸出Hello, TensorFlow!
:
>>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow!
簡單計算:
>>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42
測試結果顯示,已成功在docker中安裝Tensorflow。