I currently have two machines running Home Assistant.
I would like to use one as a “development” machine and one as a “production” machine. I can currently test on one machine, create a backup and then restore to the production machine, with some serious limitations.
Here is the problem that I hope I can solve using two Docker containers on one machine…
Both machines are on one Wifi network that includes all my devices (sensors, lights, plugs, etc.). Both machines use Home Assistant’s standard port 8123. The two machines, naturally, have different IP and MAC addresses. My router uses the IP address and MAC address of each machine, along with rest of the devices, to give them each a fixed lease.
My problem is that some of the devices, like temperature sensors, need to be set up with the IP address of the computer they will be communicating with and it is a bit of a chore to change this setting back and forth on each device manually and it means that the devices can only work with one of the machines at a time. Testing the devices on the test machine means they will be offline on the production machine and vice versa.
I would like to know if it is possible for two docker containers on one host machine to share the host machine’s IP and MAC address and have different ports. This would preserve the fixed lease on the router and should allow me to switch from test to production by just using a different port. This would allow me to set up the devices like sensors that require an IP address of the host to work in both the test and production environment.
Starting two Docker containers with different ports on one host is not a problem.
Install Docker on the host machine and then start two containers with:
docker run -d --name=homeassistant-prod -p 8123:8123 homeassistant/home-assistant
docker run -d --name=homeassistant-dev -p 8124:8123 homeassistant/home-assistant
First port after -p is the port on the host and the port after the colon is the port of the contianer in this case it is the default port (8123) of Home Assistant. You can match the port on the host to any port you want.
Thank you for your reply. I know very little about docker except that it is one on the options for running Home Assistant. I have not yet installed it on a test machine.
What I think I need is:
docker run -d --name=homeassistant-prod -p 8123:8123 homeassistant/home-assistant
docker run -d --name=homeassistant-dev -p 8124:8124 homeassistant/home-assistant
In other words, I would be able to access the “production” Home Assistant container over the network using the standard url:
192.168.1.100:8123
If I wanted to work on the “development” Home Assistant container over the network I would use:
192.168.1.100:8124
Internally, on both containers, the various sensors on the network would connect to 192.168.1.100
I do not know enough about docker to know if this possible.
Normally, the internal ports of a Cointainer are not accessible from the host. Only if you use port mapping.
If 192.168.1.100 is your host ip adress than
docker run -d --name=homeassistant-prod -p 8123:8123 homeassistant/home-assistant
docker run -d --name=homeassistant-dev -p 8124:8123 homeassistant/home-assistant
will do the job. You can reach the “production” Home Assasin installation under 192.168.1.100:8123. Docker will forward the port 8123 to 8123. And the “development” Home Assasin installation under 192.168.1.100:8124. Docker will forward the port 8124 to 8123. There is no need to change the Port of Home Assistant.