What is the right way to configure eclipse-mosquitto in a docker-compose file so that it uses a mosquitto.conf file in a volume?
No matter how I configure my docker-compose.yml file in order to run eclipse-mostquitto using a custom mosquitto.conf file, I keep getting a variation on the following error message:
# docker-compose up eclipse-mosquitto
server_eclipse-mosquitto_1 is up-to-date
Attaching to server_eclipse-mosquitto_1
eclipse-mosquitto_1 | chown: /mosquitto/config: Permission denied
eclipse-mosquitto_1 | 1650310347: Error: Unable to open config file /mosquitto/config/mosquitto.conf.
I've tried ever suggestion in https://github.com/eclipse/mosquitto/issues/1078 but I keep getting that error.
Is there an 'official' supported way to configure eclipse-mosquitto as a member of a docker-compose?
I have mine setup like this:
mosquitto:
image: eclipse-mosquitto
container_name: mosquitto_broker
volumes:
- ./mosquitto/:/mosquitto/:rw
ports:
- 1883:1883
- 9001:9001
networks:
- default
and then a folder structure like this:
- docker compose
- mosquitto
- config
- mosquitto.conf
- config
Who are the owners and what are the permissions on the files? That appears to be where my system is stumbling.
I tried your config. (All files owned by root with normal permissions:
# docker-compose up mosquitto
Creating mosquitto_broker ... done
Attaching to mosquitto_broker
mosquitto_broker | chown: /mosquitto: Permission denied
mosquitto_broker | 1650595839: Error: Unable to open config file /mosquitto/config/mosquitto.conf.
mosquitto_broker exited with code 3
I tried your config. (All files owned by root with normal permissions:
# docker-compose up mosquitto Creating mosquitto_broker ... done Attaching to mosquitto_broker mosquitto_broker | chown: /mosquitto: Permission denied mosquitto_broker | 1650595839: Error: Unable to open config file /mosquitto/config/mosquitto.conf. mosquitto_broker exited with code 3
yeah, that's weird. everyone on my team is doing the same thing with no permission problems.
have you tried running docker-compuse up as sudo?
The same here. No matter what I try, there is always the chown: /mosquitto/config/mosquitto.conf: Permission denied error.
@danielmoncada Running with sudo is not an option. I don't have that privileges available. Anyway, I believe it should be possible to mount a conf file into container without such errors..
To me the root cause of the problem seems to be in how the container is behaving the file - it is trying to chown a file, which is supposed to be bind-mounted from host. That is not the correct behavior, is it?
I was able to resolve mine by doing the following two things:
- NOT SURE IF THIS STEP NEEDED,
chmod 777 -R .in the folder with my compose file. - I added an empty config file at
./mosquitto/config/mosquitto.confin my local side of the volume. I guess the container won't attempt to make a new config file when starting up?
You'll need to fill in some blanks on the config file per https://mosquitto.org/man/mosquitto-conf-5.html
I have the same problem on MacOS Colima vz / docker setup. 777 is never a good idea (and doesn't fix the problem either) anywhere and the :rw appended does not change anything.
docker compose up mosquitto [+] Running 1/1 ✔ Container mosquitto Recreated 0.0s Attaching to mosquitto mosquitto | chown: /mosquitto/.DS_Store: Permission denied mosquitto | chown: /mosquitto/config/mosquitto.conf: Permission denied mosquitto | chown: /mosquitto/config: Permission denied mosquitto | chown: /mosquitto/config: Permission denied mosquitto | chown: /mosquitto/log/mosquitto.log: Permission denied mosquitto | chown: /mosquitto/log: Permission denied mosquitto | chown: /mosquitto/log: Permission denied mosquitto | chown: /mosquitto/data/mosquitto.db: Permission denied mosquitto | chown: /mosquitto/data: Permission denied mosquitto | chown: /mosquitto/data: Permission denied mosquitto | chown: /mosquitto: Permission denied mosquitto | chown: /mosquitto: Permission denied mosquitto | 1744990253: Warning: File /mosquitto/data//mosquitto.db owner is not mosquitto. Future versions will refuse to load this file.To fix this, use
chown mosquitto /mosquitto/data//mosquitto.db. mosquitto | 1744990253: Warning: File /mosquitto/data//mosquitto.db group is not mosquitto. Future versions will refuse to load this file. Gracefully stopping... (press Ctrl+C again to force) [+] Stopping 1/1 ✔ Container mosquitto Stopped
mosquitto: image: eclipse-mosquitto container_name: mosquitto volumes: - ./mosquitto/:/mosquitto/:rw ports: - 1883:1883 - 9001:9001