Summary
Docker Compose does not support setting fixed MAC addresses for containers using external Macvlan networks, despite documentation suggesting it should work as of Docker v2.24.0+.
Environment
- Docker version: 29.1.3, build f52814d
- Docker Compose version: 1.29.2, build 5becea4c
- Network driver: macvlan (external network)
- OS: Ubuntu 24.04.3 LTS (kernel 6.8.0-90-generic)
Problem
Containers on Macvlan networks receive random MAC addresses on every recreation, making network management (DHCP reservations, statistics, firewall rules) based on MAC addresses impossible.
What I’ve Tried
1. Service-level mac_address (Documented in Compose File reference)
services:
containerxyz:
mac_address: "02:42:0a:00:46:27"
networks:
macvlan:
ipv4_address: 192.168.70.27
Result: Deploys successfully, but MAC address is ignored - random MAC assigned
2. Network-level mac_address (Recommended in docs for Engine v25+)
services:
containerxyz:
networks:
macvlan:
ipv4_address: 192.168.70.27
mac_address: "02:42:0a:00:46:27"
Result: Either “.networks.macvlan contains unsupported option: ‘mac_address’” error (without quotation marks around the mac address) OR the container deploys but MAC is ignored (if entered with quotation marks like in the example above).
3. Manual docker network connect with MAC
docker network connect --ip 192.168.70.27 --mac-address 02:42:0a:00:46:27 Macvlan containerxyz
Result: unknown flag: --mac-address - flag not available in Docker 29.1.3
4. Driver options workaround
docker network connect --ip 192.168.70.27 --driver-opt "com.docker.network.endpoint.macaddress=02:42:0a:00:46:27" Macvlan containerxyz
Result: Deploys but MAC still random
What Works
Portainer Duplicate/Edit supports setting a mac address, but this bypasses my CI pipeline and makes it really hard to maintain.
docker run --mac-address apparently also supports fixed MAC addresses, but this bypasses Docker Compose entirely.
Request
Please implement one of the following:
- Make Compose honor
mac_addresssetting for Macvlan networks (as documentation suggests) - Document the limitation clearly if this is intentional behavior
- Add
--mac-addressflag todocker network connect(then I could do it as a last step workaround in my deploy scripts.)
Currently forced to choose between Docker Compose (maintainability) or fixed MAC addresses (network management).