Docker Community Forums

Share and learn in the Docker community.

Assign static IP to docker container in macvlan network

Hello guys, I’m trying to assign static IP addresses to my docker containers in my macvlan network because every time I restart the docker instance (e.g for an update) o I restart the containers in that network all the IPs get messed up and this is a problem since my AdGuard Home DNS service changes its IP. I use to create the containers through stack in Portainer. Everything is running on a Synology NAS.

This is the conf that I tried to use, reading here and there it was the most suggested solution, but with this one docker-compose tries to create another network called “adguard_macvlan” but that it’s something that I don’t want since I already have my macvlan network.

version: '3.8'
services:
  adguard:
    container_name: AdGuard
    networks:
      macvlan:
        ipv4_address: 10.10.10.251
    image: adguard/adguardhome
    volumes:
      - /volume1/docker/adguard/data:/opt/adguardhome/work
      - /volume1/docker/adguard/config:/opt/adguardhome/conf
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "80:80/tcp"
server
      - "3000:3000/tcp"
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

networks:
 macvlan:
  driver: macvlan
  driver_opts: eth0
    ipam:
     config: 
       - subnet: 10.10.10.0/24
         gateway: 10.10.10.1 

Thanks for your help.