Portainer Stack:
```yaml
---
version: "3.9"
services:
  mqtt:
    container_name: mqtt
    hostname: mqtt
    image: eclipse-mosquitto:${TAG-latest}
    restart: ${RST-unless-stopped}
    network_mode: ${NET-bridge}
    user: "1000:1000"
    environment:
      - TZ=${TZ-Europe/Amsterdam}
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /mqtt/config:/mosquitto/config
      - /mqtt/data:/mosquitto/data
      - /mqtt/log:/mosquitto/log
    ports:
      - 9001:9001
      - 1883:1883
    labels:
      - com.centurylinklabs.watchtower.enable=${AutoUpdate-true}
```


Environments:
```
TAG=latest
RST=unless-stopped
NET=bridge
PUID=${PUID-1000}
PGID=${PGID-1000}
TZ=${TZ-Europe/Amsterdam}
AutoUpdate=true
```

Mosquitto configuration file `/mosquitto/config/mosquitto.conf`:
```
listener 1883

persistence true
persistence_location /mosquitto/data/

log_dest file /mosquitto/log/mosquitto.log
log_dest stdout
log_type all

allow_anonymous false
password_file /mosquitto/config/passwd
```

Create empty file `/mosquitto/config/passwd`
And from the terminal create user sending:  

```
docker exec -it mqtt usr/bin/mosquitto_passwd -c /mosquitto/config/passwd USERNAME
```

And if you want to add more users use:

```
docker exec -it mqtt usr/bin/mosquitto_passwd -b /mosquitto/config/passwd NEW_USERNAME PASSWORD
```
