-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Hello all,
I'm trying to create a simple test setup with mosquitto and docker, but I'm getting a lot of trouble with the password file.
I'm creating it within the container, but as soon as I insert it into the config file, the container won't start any more.
Apologies in advance for all the text, I'm trying to make this as clear as possible; Here the steps I have done:
- Structure:
/srv/mosquitto/
├── compose.yaml
├── config
│ └── mosquitto.conf
├── data
└── log- compose.yaml:
services:
mosquitto:
image: eclipse-mosquitto
container_name: mosquitto
volumes:
- ./config:/mosquitto/config
- ./data:/mosquitto/data
- ./log:/mosquitto/log
ports:
- 1883:1883
- 9001:9001
stdin_open: true
tty: true- config/mosquitto.conf:
listener 1883
listener 9001
protocol websockets
persistence true
persistence_file mosquitto.db
persistence_location /mosquitto/data/
#Authentication
allow_anonymous false
#password_file /mosquitto/config/pwfile-> Note that password_file is commented out at this point
Now i ran it with docker compose up -d
4. log:
mosquitto | 1773868970: Info: running mosquitto as user: mosquitto.
mosquitto | 1773868970: mosquitto version 2.1.2 starting
mosquitto | 1773868970: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto | 1773868970: Bridge support available.
mosquitto | 1773868970: Persistence support available.
mosquitto | 1773868970: TLS support available.
mosquitto | 1773868970: TLS-PSK support available.
mosquitto | 1773868970: Websockets support available.
mosquitto | 1773868970: Opening ipv4 listen socket on port 1883.
mosquitto | 1773868970: Opening ipv6 listen socket on port 1883.
mosquitto | 1773868970: Opening ipv4 listen socket on port 9001.
mosquitto | 1773868970: Opening ipv6 listen socket on port 9001.
mosquitto | 1773868970: mosquitto version 2.1.2 running-> so far so good
5. Switch inside the container and create an password file:
root@mycomputer:/srv/mosquitto# docker exec -it mosquitto sh
/ # cd mosquitto/config/
/mosquitto/config # ls -alF
total 12
drwxr-xr-x 2 root root 4096 Mar 18 21:28 ./
drwxr-xr-x 5 mosquitto mosquitto 4096 Feb 9 20:01 ../
-rw-r--r-- 1 root root 212 Mar 18 21:19 mosquitto.conf
/mosquitto/config # mosquitto_passwd -c -b ./pwfile secretuser verysecretpassword
Adding password for user secretuser
/mosquitto/config # ls -alF
total 16
drwxr-xr-x 2 root root 4096 Mar 18 21:29 ./
drwxr-xr-x 5 mosquitto mosquitto 4096 Feb 9 20:01 ../
-rw-r--r-- 1 root root 212 Mar 18 21:19 mosquitto.conf
-rw------- 1 root root 197 Mar 18 21:29 pwfile
/mosquitto/config # exit- enable password file in mosquito.conf:
listener 1883
listener 9001
protocol websockets
persistence true
persistence_file mosquitto.db
persistence_location /mosquitto/data/
#Authentication
allow_anonymous false
password_file /mosquitto/config/pwfile- When I'm trying to fire up the container, it creates this log:
mosquitto | 1773869758: Info: running mosquitto as user: mosquitto.
mosquitto | 1773869758: Restored 0 base messages
mosquitto | 1773869758: Restored 0 retained messages
mosquitto | 1773869758: Restored 0 clients
mosquitto | 1773869758: Restored 0 subscriptions
mosquitto | 1773869758: Restored 0 client messages
mosquitto | 1773869758: mosquitto version 2.1.2 starting
mosquitto | 1773869758: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto | 1773869758: Bridge support available.
mosquitto | 1773869758: Persistence support available.
mosquitto | 1773869758: TLS support available.
mosquitto | 1773869758: TLS-PSK support available.
mosquitto | 1773869758: Websockets support available.
mosquitto | 1773869758: password-file: Error: Unable to open pwfile "/mosquitto/config/pwfile".
mosquitto | 1773869758: mosquitto version 2.1.2 terminating
mosquitto | 1773869758: Saving in-memory database to /mosquitto/data//mosquitto.db.
mosquitto exited with code 13- After doing
chmod 0700 pwfile:
mosquitto | 1773869919: Info: running mosquitto as user: mosquitto.
mosquitto | 1773869919: Restored 0 base messages
mosquitto | 1773869919: Restored 0 retained messages
mosquitto | 1773869919: Restored 0 clients
mosquitto | 1773869919: Restored 0 subscriptions
mosquitto | 1773869919: Restored 0 client messages
mosquitto | 1773869919: mosquitto version 2.1.2 starting
mosquitto | 1773869919: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto | 1773869919: Bridge support available.
mosquitto | 1773869919: Persistence support available.
mosquitto | 1773869919: TLS support available.
mosquitto | 1773869919: TLS-PSK support available.
mosquitto | 1773869919: Websockets support available.
mosquitto | 1773869919: password-file: Error: Unable to open pwfile "/mosquitto/config/pwfile".
mosquitto | 1773869919: mosquitto version 2.1.2 terminating
mosquitto | 1773869919: Saving in-memory database to /mosquitto/data//mosquitto.db.
mosquitto exited with code 139 Additionally chown mosquitto:mosquitto pwfile:
root@mycomputer:/srv/mosquitto# ls -alF config/
total 16
drwxr-xr-x 2 root root 4096 Mar 18 22:34 ./
drwxr-xr-x 5 root root 4096 Mar 18 21:53 ../
-rw-r--r-- 1 root root 211 Mar 18 22:34 mosquitto.conf
-rwx------ 1 mosquitto mosquitto 197 Mar 18 22:29 pwfile*
root@mycomputer:/srv/mosquitto# docker compose up
Attaching to mosquitto
mosquitto | 1773870429: Info: running mosquitto as user: mosquitto.
mosquitto | 1773870429: Restored 0 base messages
mosquitto | 1773870429: Restored 0 retained messages
mosquitto | 1773870429: Restored 0 clients
mosquitto | 1773870429: Restored 0 subscriptions
mosquitto | 1773870429: Restored 0 client messages
mosquitto | 1773870429: mosquitto version 2.1.2 starting
mosquitto | 1773870429: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto | 1773870429: Bridge support available.
mosquitto | 1773870429: Persistence support available.
mosquitto | 1773870429: TLS support available.
mosquitto | 1773870429: TLS-PSK support available.
mosquitto | 1773870429: Websockets support available.
mosquitto | 1773870429: password-file: Error: Unable to open pwfile "/mosquitto/config/pwfile".
mosquitto | 1773870429: mosquitto version 2.1.2 terminating
mosquitto | 1773870429: Saving in-memory database to /mosquitto/data//mosquitto.db.
mosquitto exited with code 13Also when I'm running the container with disabled file in the config, switch the container terminal and do cat /mosquitto/config/pwfile it can access the file without any problem (I've copied the path from the error message)
I’ve already read and tried several troubleshooting tips for this; either I don’t understand what ultimately led to the solution, or the solution didn’t work for me, which is why I’ve tried to describe the issue in as much detail as possible, so sorry again for the long text