Docker容器之间的IPC通信 [英] IPC communication between Docker containers

查看:1039
本文介绍了Docker容器之间的IPC通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个单独的Docker容器是否可以通过ZMQ IPC套接字进行通信?如果是这样,如何实现?

Is it possible for two separate Docker containers to communicate over a ZMQ IPC socket? If so, how can this be achieved?

例如:

Docker容器#1 执行创建ZMQ响应套接字并绑定到"ipc://tmp/service_name"的应用程序.

Docker Container #1 executes an application that creates a ZMQ Response socket and binds to "ipc://tmp/service_name".

Docker Container#2 执行创建ZMQ Request套接字并连接到"ipc://tmp/service_name"的应用程序.

Docker Container #2 executes an application that creates a ZMQ Request socket and connects to "ipc://tmp/service_name".

以下命令用于在两个单独的Docker容器中运行应用程序:

The following commands are used to run the applications in two separate docker containers:

// Run container #1 (binds to "ipc://tmp/service_name")
docker run --name c1 -it container1

// Run container #2 (connects to "ipc://tmp/service_name")
docker run -it --link c1:container1 --name c2 container2

运行容器后,我无法建立ZMQ(IPC)连接.但是,我能够从容器2 ping容器1,并从容器1 ping容器2.

After running the containers, I am not able to establish the ZMQ (IPC) connection. However, I am able to ping container 1 from container 2, and ping container 2 from container 1.

我也尝试使用--ipc命令,但没有帮助:

I also tried using the --ipc command, but it did not help:

// Run container #1 (binds to "ipc://tmp/service_name")
docker run --name c1 --ipc=host -it container1

// Run container #2 (connects to "ipc://tmp/service_name")
docker run -it --link c1:container1 --ipc=container:c1 --name c2 container2

更新: 我能够使用ZMQ TCP套接字在两个单独的Docker容器之间进行通信,但仍然无法使用IPC套接字进行通信.有可能吗?

UPDATE: I am able to communicate between two separate Docker containers using a ZMQ TCP socket, but am still unable to communicate using an IPC socket. Is it possible?

推荐答案

您是否看到过

Have you seen Shared Memory with Docker containers (docker version 1.4.1)? It sounds like you need to share the volume where the IPC lives and also set --ipc host. In your example, it would be something like:

# Container #1
docker run -it --name c1 -v /tmp:/tmp --ipc=host container1

# Container #2
docker run -it --name c2 -v /tmp:/tmp --ipc=host container2

这篇关于Docker容器之间的IPC通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆