How to make docker container invoke another container on a target host docker machine of a docker swarm

I am working with docker swarm of three nodes.
In which there is a service “controller” which in turn invokes other containers on demand using python docker SDK. I am able to get it working by mounting /var/run/docker.sock:/var/run/docker.sock.

But now when I setup 3 replicas of “controller” service, constraining them to run each on unique host. I am not able to mount /var/run/docker.sock of each host in the docker swarm, which will enable the controller service to invoke container services on demand on each docker machine.

In other words, I want to target a host docker machine of the swarm, to invoke on-demand container via the controller service.

Can you please suggest any workaround for this problem?

Thanks!

Hi!

It’s not possible to choose a target host since that hosts are “active”.

But if you turn all the hosts to the “drain mode” and just one host as “active”, you will be able to do it.

For example, if you have 3 hosts:
-host1 (drain)
-host2 (drain)
-host3 (active)

Then you will be able to invoke on-demand container in the host3.

Use this command: docker node update --availability (drain/active) $NODE_NAME

If you have any questions, ask me, please!

Renan Pitz.