Docker Swarm macvlan Setup for Static IPs Fails with "Gateway Address Already in Use"

Hi everyone,

We’re working on a setup where specific containers in Docker Swarm need to have static IP addresses. To achieve this, we’re using macvlan networks, alongside HAProxy for load balancing across these services.

Our approach involves creating a unique macvlan network for each service as follows:

  1. Config-Only Network Creation (on all Swarm servers):

bash

Copy code

docker network create -d macvlan --config-only --subnet=192.168.110.0/24 --gateway=192.168.110.1 --ip-range=192.168.110.12/32 parent=ens193 app01
  1. Swarm Network Creation (on manager):

bash

Copy code

docker network create -d macvlan --scope swarm --config-from app01 swarm_app01

For new applications, we add additional virtual network adapters (e.g., ens224) and assign new networks with static IPs.

The issue is that, after successfully setting up and running four IPs and networks, any attempt to create a fifth network now results in the following error:

css

Copy code

failed to allocate gateway (192.168.110.1): address already in use

We’re running Docker version 27.1.2 (build d01f265).

Is anyone familiar with this error, or does anyone have alternative suggestions for assigning static IPs to services within a Docker Swarm? Any help or insight would be appreciated!

Swarm does not allow assigning fixed ip’s, so people often come up with the idea of creating macvlan networks with an ip range that covers a single specific ip like you did. This approach works for exactly a single container, as only a single macvlan network can be created for a specific gateway.

With docker compose on the other hand, the macvlan could use a larger ip-range, and each service could use a specific ipv4 address.

1 Like