0

We're starting to implement docker swarm or some of the parts of our application. One of these parts is a web socket server which allows us to push "live" content to a particular user.

My question is - if I want to make a rest call to particular container, and not a load balanced one on the overlay network - is that possible? If so, how would I go about doing it?

Thanks

Ben

Ben Cummins
  • 498
  • 3
  • 6
  • I'm not sure if Swarm is applicable for a use case like yours. Do you want your container to be deployed/load balanced in several replicas and let Swarm manage relocation of containers, if need be? Your use case doesn't sound like you want such dynamic behaviour. – gesellix Sep 19 '17 at 20:49
  • Is your issue about making a request to a particular container or more about pending connections you'd like to keep? – gesellix Sep 19 '17 at 20:51
  • I have a load balanced "proxy" - I want to send an API call to each running instance in order to pass something on to the clients connected to that container – Ben Cummins Sep 19 '17 at 20:53

1 Answers1

1

If I understood your use case correctly, the following example might help you started.

Given an overlay network and a service with several replicas:

docker network create --driver overlay --attachable nginx
docker service create --name nginx --network nginx --replicas 3 nginx:alpine

You can run a container attached to the nginx network:

docker run --rm -it --network nginx alpine:edge ash

Inside that container you can find all tasks for the service like this:

apk add -U drill
drill tasks.nginx

The response should contain something similar to this:

...
;; ANSWER SECTION:
tasks.nginx.    600 IN  A   10.0.1.3
tasks.nginx.    600 IN  A   10.0.1.4
tasks.nginx.    600 IN  A   10.0.1.5
...

You don't really need the attachable network and the single container, though. Alternatively you could also create another service in the same network like nginx and let that service perform the tasks.<service-name> lookup to perform the actions to need.

gesellix
  • 3,024
  • 28
  • 31
  • Can I access an exact container by using the IP there? – Ben Cummins Sep 19 '17 at 21:33
  • 1
    I think Im trying to do something around the main design of swarm - I think what I am going to look at now, is using redis or similar for pub/sub and make all proxys connect to redis and subscribe for certain channels - and then when I want to send a single command to all containers, I can just publish it there. – Ben Cummins Sep 19 '17 at 21:34
  • Thank you, this was exactly what I needed! – Ben Cummins Sep 22 '17 at 15:34