HA portainer stack with different IP

I have a Debian Server with Portainer with an IP address of 192.168.1.6. with VLANs configured.

I will like to have have Home Assistant on a docker compose stack with IP 10.10.10.6 on a separate VLAN, how can I do that?

this is the standard stack:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/HomeAssistant/config:/config
      - /home/frigate/config:/config 
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

network_mode: host generally means the container inherits the host’s network address.

You could use a VM, configured how you like. Given that you are running Debian, you could install Proxmox.

I actually prefer to use Docker vs VMs

Found this example using macvlan however its pretty complex, I was looking for a simplier solution:

https://www.reddit.com/r/portainer/comments/m7pjcy/unique_ip_address_per_container/

version: 2

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    mac_address: d0:ca:ab:cd:ef:05
    cap_add:
      - NET_ADMIN
    networks:
      macvlan_NET:
        ipv4_address: 192.168.0.240
    ports:
      - 443/tcp
      - 53/tcp
      - 53/udp
      - 67/udp
      - 80/tcp
    environment:
      ServerIP: 192.168.0.240
      WEBPASSWORD: "password"
      DNS1: 127.0.0.1
      DNS2: 1.1.1.1
DNS service like 1.1.1.1
      TZ: Europe/Vienna
    volumes:
      - /home/pi/portainer/pihole:/etc/pihole
      - /home/pi/portainer/pihole/dnsmasq.d:/etc/dnsmasq.d
    restart: always

networks:
  macvlan_NET:
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: 192.168.0.1/24
          gateway: 192.168.0.1
          ip_range: 192.168.0.240/28
          aliases: pihole.home

Better start reading here I think Host network driver | Docker Docs

Trying this:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/HomeAssistant/config:/config
      - /home/frigate/config:/config 
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
#    network_mode: host
    networks:
      macvlan_iot:
        ipv4_address: 192.168.20.4
#    environment:
#      ServerIP: 192.168.20.4
#      WEBPASSWORD: "kjahsd7asidasmduae7876"
#      DNS1: 127.0.0.1
#      DNS2: 1.1.1.1

networks:
  macvlan_iot:
    driver: macvlan
    driver_opts:
      parent: eno1    
    ipam:
      config:
        - subnet: 192.168.20.0/24
          gateway: 192.168.20.1
          ip_range: 192.168.20.4/32      

However it does not work and I get this errors in the log:

s6-rc: info: service legacy-services successfully started
2023-09-19 11:25:33.743 ERROR (Thread-5) [pychromecast.socket_client] [Bedroom Display(192.168.20.56):8009] Failed to connect to service ServiceInfo(type='mdns', data='google-nest-hub-220015da2323da5406e50407810f2d2f._googlecast._tcp.local.'), retrying in 5.0s
2023-09-19 11:25:33.744 ERROR (Thread-4) [pychromecast.socket_client] [Kitchen Display(192.168.20.133):8009] Failed to connect to service ServiceInfo(type='mdns', data='google-nest-hub-aa53b3b5b0e6426d7024a349b9ea910e._googlecast._tcp.local.'), retrying in 5.0s
2023-09-19 11:25:33.745 ERROR (Thread-6) [pychromecast.socket_client] [Office Display(192.168.20.145):8009] Failed to connect to service ServiceInfo(type='mdns', data='google-nest-hub-c975dce30eed835d290ed2de9ae283fa._googlecast._tcp.local.'), retrying in 5.0s
2023-09-19 11:25:35.690 ERROR (MainThread) [homeassistant.components.homeassistant_alerts] Error requesting homeassistant_alerts data: Cannot connect to host alerts.home-assistant.io:443 ssl:default [Try again]

Similar issues:

The errors means nothing in regards to container IP. Just says HA cannot connect to some devices but ip may be what you want.

Since you use portainer you can confirm the container IP in portainer ui.

Your subnet is also wrong. I Can not remember what it shoukd be for /32 ip range but at least something like 255.255.255.255. Sure you dont want /24 and 255.255.255.0?