Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqtt on docker, no file created in volumes #1958

Open
adizag opened this issue Dec 16, 2020 · 7 comments
Open

mqtt on docker, no file created in volumes #1958

adizag opened this issue Dec 16, 2020 · 7 comments

Comments

@adizag
Copy link

adizag commented Dec 16, 2020

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
Copy link
Contributor

ralight commented Dec 17, 2020

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
Copy link
Author

adizag commented Dec 17, 2020

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
Copy link

Edo78 commented Jan 4, 2021

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
Copy link

denwald commented Feb 5, 2021

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
Copy link
Contributor

ralight commented Feb 5, 2021

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

1958

@denwald
Copy link

denwald commented Feb 5, 2021

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
Copy link
Contributor

ralight commented Feb 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants