Assign multiple IPs to same docker container using macvlan (or by any other method)

Tags: #<Tag:0x00007f326ea14f58>

Hi All,
Not related to HA but I know this community is full of experts. So worth to ask.
I have currently 2 networks created using macvlan running over my synology. These networks are physically seprated and completely isolated. So device on one network can not communicate to other.

    [email protected]:/# docker network ls
    NETWORK ID      NAME               DRIVER              SCOPE
    12434567        priNet             macvlan             local
    76543210        secNet             macvlan             local

I am using these networks as my primary home network and other for my smart home devices. I am able to attach any docker container to any of them. However, now I would like to attach some containers to both of them.
So I updated my docker-compose to attach container to both networks.

    version: "3.7"
    
    services:
      container:
        image: someImage:latest
        environment:
          TZ: 'Europe/Berlin'
        volumes:
           - /etc/localtime:/etc/localtime:ro
        restart: always
        networks:
          int_homeNet:
            ipv4_address: 192.1.1.21
          int_smartNet:
            ipv4_address: 192.1.2.21
            
    networks:
      int_homeNet:
        external: true
        name: priNet
      int_smartNet:
        external: true
        name: secNet

After running this docker compose file, I get following error

level=fatal msg=\\\\\\\"failed to add interface dockerb21a0fc to sandbox: error setting interface \\\\\\\\\\\\\\\"dockerb21a0fc\\\\\\\\\\\\\\\" IP to 192.168.2.21/24: cannot program address 192.168.2.21/24 in sandbox interface because it conflicts with existing route {Ifindex: 194 Dst: 192.168.176.0/22 Src: 192.168.1.21 Gw: <nil> Flags: [] Table: 254}\\\\\\\"\\\\n\\\"\"": unknown

Do you think if what I am doing is right way to do it ? Or is it even technically possible ? I am also fine to achive same thing by some other way…

Many thanks for your all of your suggestions…

Try to set address spaces used in your networks explicitly with “subnet” clause in “networks” section

@reedcat,
many thanks for your reply. (Your first post, and first response to query !!!
Do you mind to put an example. I tried some and it did failed.