The Goal
Run a single haproxy container in the swarm with a static IP on my LAN that will be recreated if a node fails. In essence, it would be akin to a VIP pointing to haproxy but without requiring an external load balancer outside of the swarm.
What works - local macvlan
Example: Creating the macvlan networks on two nodes, running the container on node1, stopping the container, then running the container on node2. The haproxy container is created with the same static IP and is accessible on the LAN.
What doesn't work - swarm macvlan
Example: Setting the macvlan network scope to swarm, then deploying the stack. Container is not visible to the network.
Files used in example
docker-compose.yml:
version: "3.2"
networks:
vlan0:
external: true
services:
haproxy:
image: haproxy:2.3.2-alpine
container_name: haproxy
volumes:
- ./data:/usr/local/etc/haproxy:ro
environment:
- TZ=America/Los_Angeles
restart: always
networks:
vlan0:
ipv4_address: 192.168.0.201
localnet.sh (script to stop stack / remove network / recreate network as local / run container local):
#!/bin/bash
docker service rm haproxy_haproxy
docker-compose down
docker network rm vlan0
docker network create -o parent=eth0 --subnet 192.168.0.0/24 --gateway 192.168.0.1 --driver macvlan --scope local vlan0
docker-compose up
swarmnet.sh (script to remove container and network / recreate network as swarm / run as swarm stack):
#!/bin/bash
docker service rm haproxy_haproxy
docker-compose down
docker network rm vlan0
docker network create -o parent=eth0 --subnet 192.168.0.0/24 --gateway 192.168.0.1 --driver macvlan --scope swarm vlan0
docker stack deploy -c docker-compose.yml haproxy
Is it possible to run a single container with a static macvlan IP in swarm mode?
Any help is appreciated.
Edit: I have been able to get macvlan addresses working, but docker swarm does not obey the ipv4_address field to static the container. I understand the reason for this (replicas, etc. not going on the same IP) but in this scenario, it will not happen due to it being a single container. I've found this issue discussed here: https://forums.docker.com/t/docker-swarm-1-13-static-ips-for-containers/28060/