tornado / graphlab无法在docker中分配请求的地址

时间:2017-07-27 06:00:01

标签: python sockets docker tornado graphlab

运行gl.canvas.set_target('ipynb')会在docker容器中抛出exeption。

即使gl.canvas.set_target('ipynb', port=28892)其中28892是开放端口,错误也保持不变。

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-257-3f215a521352> in <module>()
----> 1 gl.canvas.set_target('ipynb')

/opt/conda/envs/gl-env/lib/python2.7/site-packages/graphlab/canvas/utils.pyc in set_target(target, port)
    102             # and to preserve backwards compatibility/other use cases
    103             # (running a notebook exported to .py, for instance)
--> 104         _active_target = targets[target]()
    105 
    106     # track metrics on target

/opt/conda/envs/gl-env/lib/python2.7/site-packages/graphlab/canvas/target.pyc in __init__(self, port)
     25         self.state = graphlab.canvas.state.State()
     26         # TODO server is not necessary in static IPython/Jupyter Notebook
---> 27         self.server = graphlab.canvas.server.Server(self.state, port)
     28         # add data objects to left nav
     29         DataView = graphlab.canvas.views.data_objects.DataObjectsView()

/opt/conda/envs/gl-env/lib/python2.7/site-packages/graphlab/canvas/server.pyc in __init__(self, state, port)
     44 
     45         #Will raise exception if port cannot be bound
---> 46         self.__bind_socket(port)
     47 
     48     # methods

/opt/conda/envs/gl-env/lib/python2.7/site-packages/graphlab/canvas/server.pyc in __bind_socket(self, port)
     93     # Raises exception if socket cannot be bound on requested port
     94     def __bind_socket(self, port=None):
---> 95         sockets = tornado.netutil.bind_sockets(port,"localhost")
     96         self.__server.add_sockets(sockets)
     97         with self.__port_lock:

/opt/conda/envs/gl-env/lib/python2.7/site-packages/tornado/netutil.pyc in bind_sockets(port, address, family, backlog, flags, reuse_port)
    194 
    195         sock.setblocking(0)
--> 196         sock.bind(sockaddr)
    197         bound_port = sock.getsockname()[1]
    198         sock.listen(backlog)

/opt/conda/envs/gl-env/lib/python2.7/socket.pyc in meth(name, self, *args)
    226 
    227 def meth(name,self,*args):
--> 228     return getattr(self._sock,name)(*args)
    229 
    230 for _m in _socketmethods:

error: [Errno 99] Cannot assign requested address

看起来更像是一个码头/龙卷风问题而不是graphlab问题,因为在主机上同样的命令也能正常工作。

我使用以下命令启动了我的docker容器:

sudo docker run -it -v /path/to/data:/root/data \
    -v ~/code/work/src:/root/src \
    -p 8888:8888 -p 28892:28892 company/graphlab \
    /bin/bash -c "source activate gl-env && jupyter notebook --notebook-dir=~/src --ip='*' --port=8888 --no-browser"

有没有办法找出这个端口,以便我可以打开它或任何其他方式来解决这个问题?

2 个答案:

答案 0 :(得分:5)

编辑/ etc / hosts文件(在容器内)只包含localhost的1个ip地址值为我解决了这个问题。它只适用于在正在运行的容器上编辑它。在构建图像时编辑它并不能解决问题。

在容器启动时,我的/ etc / hosts包含以下行:

127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback

我必须将它们改为:

127.0.0.1   localhost
::1 ip6-localhost ip6-loopback

答案 1 :(得分:0)

ForcaeLuz的另一个答案是好的,但只能治疗症状。

似乎最近在this commit中的Tornado中已修复该问题,其中的注释非常有用(例如Docker的默认配置如何引起这种情况)。

在某些系统上(最明显的是使用默认配置的docker),ipv6被部分禁用:socket.has_ipv6为true,我们可以创建AF_INET6套接字,并且getaddrinfo(“ localhost”,...,AF_PASSIVE)解析为:: 1 ,但绑定时会出现错误。

它尚未发布(截至撰写本文时),但可以从其主分支(例如,通过运行

pip install --upgrade git+https://github.com/tornadoweb/tornado.git@master#egg=tornado

(或类似),或等待(我认为)应包含此更改的6.1.0版本。在其他一些使用龙卷风的项目中进行了尝试,并在Docker中遇到问题时,一切都很好。