Docker networking confusion

I’m running HA and multiple other containers on a single Ubuntu 20.04 server. I’ve figured out the enough of Docker to make me dangerous, but am still struggling with the networking piece.

The relevant part of my docker-compose is below. As recommended, I’ve give HA host-mode networking. However, this means (I think?) that I do need to expose influxdb port 8086 so that HA can talk to it.

Is there a way with docker-compose to give HA 2 network interfaces; one “internal” that can speak directly to influxdb, and the other the more public one I use to access it?

version: '3.7'
services:
  homeassistant:
    image: homeassistant/home-assistant:stable
    network_mode: host
  influxdb:
    image: influxdb
    networks:
      public:
    ports:
      - 8086:8086
networks:
  public:
    ipam:
      driver: default
      config:
        - subnet: "172.22.0.0/24"

So if you had a third container also in the public network, it can access the influx db by using the container name as the hostname.

But for HA to access it, because you’re exposting the 8086 port, HA will access influx with the server name that docker is running on…or in this case localhost:8086

Also you could have just used:
networks:
public:

The rest wasn’t really necessary unless there was a specific subnet you wanted.

Is there a way to get my HA container to connect to the influxdb container using docker networking? Reading further, it appears it is possible to have a container to connect to multiple networks; is this “nullified” if the container is using host mode?

Not sure, I think network_mode host trumps everything.
Is there a reason you don’t want to use the fact you’ve exposed the influxdb ports?

Which then brings up, why are you exposing those ports if you don’t want ot use them and only want to use the internal network (so you can them remove the ports section).