ZeroMQ 无法在 [0.0.0.0:5555] 上的 Docker 上执行 .bind() - 地址已被使用。为什么?
ZeroMQ fails to .bind() on Docker on [0.0.0.0:5555] - address already in use. Why?
在尝试 .bind()
上 0.0.0.0:5555
地址时 ZeroMQ 套接字有点问题,当试图 运行 它在 Docker 通过 Rancher Cattle 的容器。
每次我尝试 运行 时,我都会遇到同样的错误:
zmq.error.ZMQError: Address already in use.
试图在我的 Docker 文件中执行 EXPOSE 5555
和 EXPOSE 5555/tcp
,但没有帮助。
这是我的部分代码:
...
self.context = zmq.Context()
self.socket = self.context.socket(zmq.PUB)
self.socket.bind('tcp://%s:%d' % ('0.0.0.0', 5555))
...
也许有人遇到了同样的问题。如何解决?
ZeroMQ API 定义了 3 种方法:
Assigning a local address to a socket
When assigning a local address to a socket using zmq_bind()
with the tcp://
transport, the endpoint shall be interpreted as an interface followed by a colon and the TCP port number to use.
An interface may be specified by either of the following:
- The wild-card *, meaning all available interfaces.
- The primary IPv4 address assigned to the interface, in its numeric representation.
- The interface name as defined by the operating system.
Interface names are not standardised in any way and should be assumed to be arbitrary and platform dependent. On Win32 platforms no short interface names exist, thus only the primary IPv4 address may be used to specify an interface.
所以,至少有一个应该使工作取得进展。
经过两个小时的调试后,我尝试制作 .bind_to_random_port()
并注意到,我在 Docker 中的应用程序通过 4 个 Gunicorn
worker 启动.所以在第一个 worker 启动后,另外三个 worker 不能绑定到同一个端口。当您有多个线程或多个工作者应用程序时,请注意仅绑定到一个端口。
在尝试 .bind()
上 0.0.0.0:5555
地址时 ZeroMQ 套接字有点问题,当试图 运行 它在 Docker 通过 Rancher Cattle 的容器。
每次我尝试 运行 时,我都会遇到同样的错误:
zmq.error.ZMQError: Address already in use.
试图在我的 Docker 文件中执行 EXPOSE 5555
和 EXPOSE 5555/tcp
,但没有帮助。
这是我的部分代码:
...
self.context = zmq.Context()
self.socket = self.context.socket(zmq.PUB)
self.socket.bind('tcp://%s:%d' % ('0.0.0.0', 5555))
...
也许有人遇到了同样的问题。如何解决?
ZeroMQ API 定义了 3 种方法:
Assigning a local address to a socket
When assigning a local address to a socket usingzmq_bind()
with thetcp://
transport, the endpoint shall be interpreted as an interface followed by a colon and the TCP port number to use.
An interface may be specified by either of the following:
- The wild-card *, meaning all available interfaces.
- The primary IPv4 address assigned to the interface, in its numeric representation.
- The interface name as defined by the operating system.
Interface names are not standardised in any way and should be assumed to be arbitrary and platform dependent. On Win32 platforms no short interface names exist, thus only the primary IPv4 address may be used to specify an interface.
所以,至少有一个应该使工作取得进展。
经过两个小时的调试后,我尝试制作 .bind_to_random_port()
并注意到,我在 Docker 中的应用程序通过 4 个 Gunicorn
worker 启动.所以在第一个 worker 启动后,另外三个 worker 不能绑定到同一个端口。当您有多个线程或多个工作者应用程序时,请注意仅绑定到一个端口。