How do i setup two Home Assistant containers with docker, listening on two different ports?

I have a Ubuntu Server with Docker on my local network 192.168.86.173. I can easily install and run a Home Assistant container with:
docker run -d --name=“hass1” --restart always -v /home/myhomefolder/hass1_config:/config -e “TZ=Europe/Copenhagen” --net=host homeassistant/home-assistant
Then, from any other computer in my local network I can browse to 192.168.86.173:8123 without any problem: This is running well.
Now to my goal:
I want to use a second set of settings, this time in folder hass2_config, and for that reason I have to browse to another port, but where do I set that port?
If I use
docker run -d --name=“hass2” --restart always -v /home/myhomefolder/hass2_config:/config -e “TZ=Europe/Copenhagen” --net=host homeassistant/home-assistant
the port to call through would still be 8123 (which means conflict with container 1).
I have tried with the -p option (-p 8124:8123) but then I cannot use the option --net=host! And I MUST use --net=host in order to get discovery in configuration.yaml to work. Argh!
Does anyone have a clue on how to solve this?

You can use macvlan. This way you can assign a IP to each docker container if you want.

docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.1 --ip-range=192.168.0.80/28 -o parent=enp1s0 intranet

edit your /etc/network/interfaces:

auto enp1s0
iface enp1s0 inet manual

auto intranet
iface intranet inet static
   address 192.168.0.3
   netmask 255.255.255.0
   gateway 192.168.0.1
   pre-up ip link add link enp1s0 name intranet type macvlan mode bridge

now you can start your container as:

docker create --name="example" \
    --network=intranet \
    --ip=192.168.0.85 \
   ...
1 Like

I have exactly the same setup. You don’t need to change anything in your docker setup since you have two different config directories.

Go to your configuration.yaml file in the hass2_config directory and under the http: section put in “server_port: 8124”.

Like this:

http:
  server_port: 8124

Then your second instance will be accessible at you host IP on port 8124.

4 Likes

finity, you’re a genious! That did the trick, now I can experiment with two (or as many as I like) set of configurations. Great!

1 Like