Closed DrHoneyBear closed 3 years ago
I regard the docker-compose as a config file which anyone will edit as they wish. For instance, most users will have a MQTT broker working already, so will probably remove that section.
In your case, you will also change the appropriate address. If you want to do this with an environmental variable, that's fine, but it seems more error prone than actually putting the value in the file. You are going to have to ensure that the correct value is set in you environment whenever you start the program.
The only reason I added this docker-compose file at all was because the original author of the docker image included the mosquitto broker inside the image, and I needed to show him how to achieve the same thing with separate docker images.
I'm don't see the need to for a systemd service. Docker restarts its services on reboot anyway.
I have moved this example to the wiki page, which seems more appropriate.
Currently, your energenie_mqtt_service includes the directive:-
command: ["-h", "192.168.0.3"]
This will force mqtt clients to use 192.168.0.3. Mine runs on localhost so this would not work.
Recommend that users specify the broker host as an argument passed to docker-compose command. where docker-compose.yaml is changed to the following:-
Then, the command to spin up the container would be:-
sudo MQTT_BROKER=localhost docker-compose up -d
This assumes the environment variable MQTT_BROKER is used and of course, localhost is the broker IP - but this can be changed obviously.
Tested and working on Ubuntu and Raspbian.
And for completeness, here is the updated engmqtt.service unit file - of course this is set for localhost and runs in the /home/daz/DOCKER/ENERGENIE directory so that would need to change. Ideally these should be put in /etc/sysconfig or something as env vars and referenced in the unit file .