Is it possible for two separate Docker containers to communicate over a ZMQ IPC socket? If so, how can this be achieved?
For example:
Docker Container #1 executes an application that creates a ZMQ Response socket and binds to "ipc://tmp/service_name".
Docker Container #2 executes an application that creates a ZMQ Request socket and connects to "ipc://tmp/service_name".
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
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.
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
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?
Here's the gist: For containers to communicate with other, they need to be part of the same “network”. Docker creates a virtual network called bridge by default, and connects your containers to it. In the network, containers are assigned an IP address, which they can use to address each other.
If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.
The ipcMode parameter allows you to configure your containers to share their inter-process communication (IPC) namespace with the other containers in the task, or with the host. The IPC namespace allows containers to communicate directly through shared-memory with other containers running in the same task or host.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With