title: docker swarm macvlan network issues
body: <h1>The Goal</h1>
  <hr />
  <p>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.</p>
  <hr />
  <h2>What works - local macvlan</h2>
  <p>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.</p>
  <h2>What doesn't work - swarm macvlan</h2>
  <p>Example: Setting the macvlan network scope to swarm, then deploying the stack.  Container is not visible to the network.</p>
  <hr />
  <h3>Files used in example</h3>
  <p>docker-compose.yml:</p>
  <pre class="lang-sh prettyprint-override"><code>version: &quot;3.2&quot;
  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
  
  </code></pre>
  <p>localnet.sh (script to stop stack / remove network / recreate network as local / run container local):</p>
  <pre class="lang-sh prettyprint-override"><code>#!/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
  
  </code></pre>
  <p>swarmnet.sh (script to remove container and network / recreate network as swarm / run as swarm stack):</p>
  <pre class="lang-sh prettyprint-override"><code>#!/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
  
  </code></pre>
  <h3>Is it possible to run a single container with a static macvlan IP in swarm mode?</h3>
  <p>Any help is appreciated.</p>
  <p>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: <a href="https://forums.docker.com/t/docker-swarm-1-13-static-ips-for-containers/28060/" rel="nofollow noreferrer">https://forums.docker.com/t/docker-swarm-1-13-static-ips-for-containers/28060/</a></p>