Options to assign a static ip to a service running in docker swarm Situation:


docker swarm with 3+ nodes
service running in the swarm with replicas=1 and restart=always
swarm hosts have multiple interfaces - one for each vlan, with the same name
service is deployed as a stack 


I want to replace a service running in a VM on a static IP with the same one running docker, but I need to have the same SERVICE_IP on the ETH_SERVER interface.

What options do I have for one or more services to have static ips ?

A. added ipv4_address in docker stack yml - does not seem to be implemented in docker (at least not yet)

B. add a new host with reverse proxies to the docker stack services

C. use keepalived on the docker hosts and map SERVICE_IP - in this way if a host goes down the floating ip gets reassigned - but not sure if I could  expose ports with FLOATING_SERVICE_IP:: ...

D. ... ?

Are there any "better" ways of doing this?



I tried doing this:

on each docker host:

docker network create --config-only --subnet="&lt;CIDR&gt;" --ip-range="&lt;CIDR&gt;" -o parent="INTERFACE" "vlan_name_intermediate"


and then a global network for the whole swarm

docker network create -d macvlan --scope swarm --config-from "vlan_name_intermediate" "vlan_name"


Now if I attach a service to network "vlan_name" i can ping it from inside that vlan, but the IP is randomly assigned, not static. I tried adding this to the compose yaml file:

ipv4_address: "192.168.45.56"


where the ip is inside the CIDR ip-range, but the setting is ignored
On June 30, 2016 this issue was created on GitHub to request the implementation of static IP on docker-swarm services.

Since then multiple replies with thumbs up and down were added.

At the time of writing on December 20, 2019 this issue is open and the feature has not been implemented.

Discussion

After reading all comments I strongly doubt whether static IPs will ever be implemented in docker-swarm. On the other hand it is unclear why this issue has not been closed. If people would like to see that this feature gets implemented, one could create a Pull request or add a thumbs up to create more awareness.