I am working on setting up a new server for home-automation using a Raspberry Pi 4 and docker with docker compose. The trouble that I am having is using the eclipse mosquitto image and being able to setup the location for the mosquitto.conf file, data, and logs along with assigning a username and password for the broker.
According the information on the docker hub (link). It states that:
Configuration can be changed to:
persist data to /mosquitto/data
log to /mosquitto/log/mosquitto.log
i.e. add the following to mosquitto.conf:
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
I would like to add a folder where I have all my other docker volume information on a hard drive attached to the pi, but I can’t seem to get it to work. Does anyone know what I add to presistence_location and log_dest file location when using volumes outside of the container? Also, how do I enable usernames and passwords?
I have searched the internet and seems that I find examples that don’t work or are very hard to understand.
It is interesting that you responded to this topic, but I was actually using your docker-compose on your github last night as an example. Do you have an example on how to do this? I am a little new to docker.
Where is/srv/docker/mosquitto/config/mosquitto.conf, etc.? Like I said in my original post I have all my files on a drive that is mounted to the pi. For example my files are located in /mnt/dietpi_userdata/home-automation. In the mount there is a docker folder. From what I read in the docker hub. I need to create the mosquitto.conf file. For something so simple and used everywhere mostly in home automation there are no good beginner tutorials to setup mosquitto in docker.
you need to create directory and the file on your external drive on pi 4 .Use bind_mount to mount the required config file from
/mnt/yourdrive/*.conf on hostos’s external drive to
/mosquitto/[conf_files_locations]
inside container.
This should work already if i’m getting you right.
Okay, so I tried this out again this evening and I am able to get the container up and running, but I still have a problem. When I try to get into the containers terminal to create a username and password by the following command:
sudo docker exec -it mqtt sh
I get the following error even though portainer shows the container running:
Error response from daemon: Container 8758daf77b819eb536f22a8602dd68be7c78c9f820de1a8756990c356c684ea7 is restarting, wait until the container is running
A blank config file isn’t of much use to most applications, and this is one of those that requires options to be set in the config in order for it to work.