Categories
docker software

Using a macvlan Network in Docker Compose

Edit 2020-10-28: Update docker-compose to v1.27.0+ and you might be able to use IPAM config in a v3 compose file (Link)

Docker Compose v3+ does not support IPAM configuration (gateway, ip_range, aux_addresses) of macvlan networks.

This network definition used to work in v2, but as v3 targets Docker Swarm use cases, it was removed (NOT deprecated!?):

networks:
home-lan:
name: home-lan
driver: macvlan
driver_opts:
parent: eth0
ipam:
config:
- subnet: 192.168.1.0/24
ip_range: 192.168.1.0/24
gateway: 192.168.1.1

Tips

  • Use ip_range that matches your home network if you’d like your containers to appear with everything else on that network
  • DHCP is NOT supported for containers on macvlan networks – make sure to assign a static ipv4_address to the container if you don’t want it to conflict with something else on your network – this will create big problems

More Info:

Docker Compose Spec – IPAM: https://docs.docker.com/compose/compose-file/#ipam

Note: Additional IPAM configurations, such as gateway, are only honored for version 2 at the moment.

Docker Macvlan Tutorial: https://docs.docker.com/network/network-tutorial-macvlan/#prerequisites

Note: macvlan is NOT supported on Windows hosts

Related Links:

2 replies on “Using a macvlan Network in Docker Compose”

I don’t use ipvlan, but my best guess would be something very similar – create the network and then attach the container…
https://docs.docker.com/network/ipvlan/


networks:
home-ipvlan:
name: home-ipvlan
driver: ipvlan
driver_opts:
parent: eth0
ipam:
config:
- subnet: 192.168.1.0/24
gateway: 192.168.1.1

Leave a Reply

Your email address will not be published. Required fields are marked *