eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.16k stars 2.41k forks source link

mqtt on docker, no file created in volumes #1958

Open adizag opened 3 years ago

adizag commented 3 years ago

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:

    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/log:/mosquitto/log
        ports:
            - "1883:1883"
            - "9001:9001"
        user: "0:0"

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:

ezaguy@ezaguy-DELL:~/docker/mqtt$ ls -l -R
.:
total 8
drwxr-xr-x+ 2 root root 4096 Dec 13 00:42 data
drwxr-xr-x+ 2 root root 4096 Dec 13 00:42 log

./data:
total 0

./log:
total 0

What is wrong here? Why can't files be written?

ralight commented 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.

adizag commented 3 years ago

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?

Edo78 commented 3 years ago

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.

denwald commented 3 years ago

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.

ralight commented 3 years ago

@denwald That doesn't match what I see. It works fine without a trailing slash:

1958

denwald commented 3 years ago

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.

ralight commented 3 years ago

@denwald No problem! I'm glad it's working, it's just the trailing slash used to be required so I wanted to check.