How do I attach a macvlan network and assign a static Ip address in compose file?

I ran into the same issue while trying to get a pihole up and running on my Synology DS923+.
I hava a macvlan, named “macvlan” already in place with this specs:

IPV4 Subnet - 192.168.178.0/24
IPV4 Gateway - 192.168.178.1
IPV4 IP Range - 192.168.178.225/27

… so it has an addressable range of:

192.168.178.225 - 192.168.178.254

I wanted pihole to assign 192.168.178.225 but my pihole container always got a wrong ip address assigned by docker.

The only thing that worked for me was to have both, the ip adress defined in the “services” section and my existing macvlan listed below under the “networks” section in my compose .yml file.

services:
  pihole:
    container_name: pihole-macvlan
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
...
    networks:
      macvlan:
        ipv4_address: 192.168.178.225
...
networks:
  macvlan:
    name: 'macvlan'
    external: 'true'
1 Like