So your containers are instances of a subdomain and you got an additional nginx container loadbalancing the request to the correct containers?
LB -- B
If so, you could just drop the
ports part and use the DNS entry
wwwA being your
site name) within the loadbalancer. it will be resolved to one of the healthy
If you want to be in control yourself, you could do a DNS lookup and get all the
A entries for the particular service.
# nslookup tasks.myservice
Address 1: 127.0.0.11
Address 1: 10.0.0.13 myservice.1.ygx1zy6cuay9w3ownyplzux4w.proxy
Address 2: 10.0.0.15 myservice.2.iutlkj12kdu90s0dldkdk4dnl.proxy
That’s how Prometheus is able to scrape Docker Service btw.
- job_name: 'myservice'
- names: ['tasks.myservice']
If I missunderstood your question, this might help you going in another direction. Within
compose 3.3 you can use this:
Which does not expose a port per service, but rather use the network of the
host, thus ports are available on the host of the docker-engine.
docker run -ti --rm --net=host qnib/httpcheck curl localhost:8080
But as it uses the host network, you can only have one one container (task/process) on the host to try to bind to this port.
$ docker service update --replicas=2 http_httpcheck
$ docker logs <failed container>
[II] qnib/init-plain script v0.4.28
> execute entrypoint '/opt/entry/00-logging.sh'
> execute entrypoint '/opt/entry/10-docker-secrets.env'
[II] No /run/secrets directory, skip step
> execute entrypoint '/opt/entry/99-remove-healthcheck-force.sh'
> execute entrypoint '/opt/qnib/entry/00-delay.sh'
> Wait for 0s
> execute CMD 'go-httpcheck'
2017/10/02 09:49:40 listen tcp4 0.0.0.0:8080: bind: address already in use