Open adizag opened 3 years ago
It doesn't look like you've specified a configuration file, so the default config file will be used which doesn't do any logging nor persistence. You can fix that by adding a /mosquitto/config
volume with mosquitto.conf
in.
persistence true
persistence_location /mosquitto/data/
Running as user 0 won't matter, because Mosquitto will drop to the mosquitto
user after it starts. The volumes need to be accessible by the mosquitto
user, and will have their owner changed on starting the image to ensure this is the case.
I've added this line:
mqtt:
restart: always
hostname: mqtt
container_name: mqtt
image: eclipse-mosquitto:latest
environment:
- TZ=${TZ}
volumes:
- ${USERDIR}/docker/mqtt/data:/mosquitto/data
- ${USERDIR}/docker/mqtt/config:/mosquitto/config
- ${USERDIR}/docker/mqtt/log:/mosquitto/log
#network_mode: "bridge"
ports:
- "1883:1883"
- "9001:9001"
user: "0:0"
and this mosquitto.conf:
persistence true
persistence_file mosquitto.db
persistence_location /mosquitto/data
log_dest file /mosquitto/log/mosquitto.log
autosave_interval 30
But still, no files are written in log nor Data folders.
Is my conf right?
I have the same problem. I can't solve it but I found a workaround ...
try to change the path in your mosquitto.conf
like this
persistence_location /mosquitto/
log_dest file /mosquitto/mosquitto.log
This way the db and the log are written in your ${USERDIR}/docker/mqtt/
I really can't get why I'm unable to have the db and the log saved in subfolder but at least I was able to find a workaround.
I just ran into the same problem today. The solution was quite easy. You have to add a trailing slash to the path in mosquitto.conf like this:
persistence_location /mosquitto/data/
Without the trailing slash no .db file was created. That's on version 2.0.7 using the official docker image btw.
@denwald That doesn't match what I see. It works fine without a trailing slash:
Hello @ralight, I'm sorry. You are right. I was confused by the fact, that the .db file was not created right after the first start of the container.
@denwald No problem! I'm glad it's working, it's just the trailing slash used to be required so I wanted to check.
mosuitto installed through docker-compose on ubuntu 18.04. In mosquitto volume, I have only empty folders. no conf/db/log files are created.
This is my compose conf:
I added the user 0:0 trying to let it write stuff there but it didn’t matter
Here is an output of permissions and files in it:
What is wrong here? Why can't files be written?