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.