I have a Docker Swarm with four physical systems in it. With the following docker-compose.yml
file
version: '3.9'
services:
web1:
image: nginx
ports:
- 8080:80
I can create a web server with the command
docker stack deploy -c docker-compose.yml test
and the service is created and responds to port 8080 on all four IP addresses owned by the four physical systems. This is exactly what the Docker documentation says it will do by creating an overlay network that does mesh routing across all the nodes in the swarm.
However that is not what I want. What I want is to bind port 8080 to only one IP address on one of the nodes and direct traffic via DNS to that one address. This will allow me to use port 8080 on the other three nodes for other services. Is there a way to do this?
I have seen this question asked before, and typically the question is years old and no usable answer. One solution offered was to use iptables
rules in each host to get the intended behavior, but I see this as a maintenance problem.