Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 788|回复: 0

docker安装tensorflow环境遇到的问题与解决方案

[复制链接]
  • TA的每日心情
    奋斗
    2024-4-6 11:05
  • 签到天数: 748 天

    [LV.9]以坛为家II

    2034

    主题

    2092

    帖子

    70万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    705612
    发表于 2021-4-14 10:30:03 | 显示全部楼层 |阅读模式

    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。

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-4-19 10:04 , Processed in 0.072761 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表