mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

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?

Open spierepf opened this issue 3 years ago • 5 comments

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?

spierepf avatar Apr 18 '22 20:04 spierepf

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

danielmoncada avatar Apr 20 '22 21:04 danielmoncada

Who are the owners and what are the permissions on the files? That appears to be where my system is stumbling.

spierepf avatar Apr 22 '22 02:04 spierepf

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

spierepf avatar Apr 22 '22 02:04 spierepf

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?

danielmoncada avatar Apr 22 '22 15:04 danielmoncada

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?

AdamJel avatar Jun 13 '24 12:06 AdamJel

I was able to resolve mine by doing the following two things:

  1. NOT SURE IF THIS STEP NEEDED, chmod 777 -R . in the folder with my compose file.
  2. I added an empty config file at ./mosquitto/config/mosquitto.conf in 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

ThePrankMonkey avatar Apr 12 '25 00:04 ThePrankMonkey

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

blackandcold avatar Apr 18 '25 15:04 blackandcold