Mosquitto: Enable username and password environmental variables in docker image

Created on 3 Feb 2019  路  4Comments  路  Source: eclipse/mosquitto

Most docker images (e.g. mariadb) allow you to define settings via docker-compose. Right now, it's awkward to manage the username and password - you have to bring in an external file, and then sh into the container and run mosquitto_passwd

It looks like this repository by @thelebster does that - can these changes be merged in to the official branch?

https://github.com/thelebster/example-mosquitto-simple-auth-docker

Most helpful comment

Hi guys, I have added additional branch with an example of how to use password file.

Add passwordfile to root directory. Keep in mind that file name should be the same in .env file and in Mosquitto configuration file.

In entrypoint file I have used another command:
mosquitto_passwd -U passwordfile

Maybe configuration a little overwhelmed, just a fast example. Let me know if I could help.

All 4 comments

It sounds like you're asking to have an option of setting a single username and password, and no other users. Is that right? It doesn't sound like a great idea for the majority of users.

Correct, that's what I'm asking. Why is having something that's optional a bad idea? Most people I know have a single username/password that they use on their MQTT brokers.

Well, in the example you linked to it's not optional - the docker-entrypoint.sh will exit 1 if not provided with a username or password. Plus the mosquitto config is also hard-coded to disable anonymous access and require the password file. So it's not quite as simple as it may seem to make it optional.

Hi guys, I have added additional branch with an example of how to use password file.

Add passwordfile to root directory. Keep in mind that file name should be the same in .env file and in Mosquitto configuration file.

In entrypoint file I have used another command:
mosquitto_passwd -U passwordfile

Maybe configuration a little overwhelmed, just a fast example. Let me know if I could help.

Was this page helpful?
0 / 5 - 0 ratings