Hi,
I’m about to get crazy to have the Unifi Network Application to work.
I have two docker compose files:
One file is to create the mongodb part, unifi_db.yml
---
version: "3.1"
services:
unifi-db:
image: docker.io/mongo:4.4.18
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD_FILE : /run/secrets/mongodb_admin_user_password
container_name: unifi-db
volumes:
- db_data:/data/db
# - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
restart: unless-stopped
secrets:
- mongodb_admin_user_password
volumes:
db_data:
secrets:
mongodb_admin_user_password:
file: /etc/docker/mongodb_admin_user_password.txt
The other one to instantiate the Unifi Network Application:
---
version: "3.1"
services:
unifi-network-application:
image: lscr.io/linuxserver/unifi-network-application:latest
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Amsterdam
- MONGO_USER=unifi
- FILE__MONGO_PASS=/run/secrets/mongodb_unifi_user_password
- MONGO_HOST=unifi-db
- MONGO_PORT=27017
- MONGO_DBNAME=unifi
- MEM_LIMIT=1024 #optional
- MEM_STARTUP=1024 #optional
volumes:
- db_data:/data/db
ports:
- 8443:8443
- 3478:3478/udp
- 10001:10001/udp
- 8080:8080
- 1900:1900/udp #optional
- 8843:8843 #optional
- 8880:8880 #optional
- 6789:6789 #optional
- 5514:5514/udp #optional
restart: unless-stopped
secrets:
- mongodb_unifi_user_password
volumes:
db_data:
secrets:
mongodb_unifi_user_password:
file: /etc/docker/mongodb_unifi_user_password.txt
Both compose files work fine.
Once the mongodb container is up and running, I connected to it with:
mongo -u admin -p
I enter my password and I’m in. Here I executed the following command to create a user called unifi, owner of a db called unifi:
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "KJDNFWI4R3R", roles: [{role: "dbOwner", db: "unifi"}, {role: "dbOwner", db: "unifi_stat"}]});
And I get a successful response:
Successfully added user: {
"user" : "unifi",
"roles" : [
{
"role" : "dbOwner",
"db" : "unifi"
},
{
"role" : "dbOwner",
"db" : "unifi_stat"
}
]
}
However, the Unifi Network application can’t connect to the database!
I can’t understand what I’m doing wrong. I looked everywhere and I really can’t get the connection to work.
In the logs from the Unifi Network Application I see this:
[2023-10-17 17:25:10,082] <launcher> INFO db - Connecting to mongodb://unifi:~MONGO_PASS~@unifi-db:27017/unifi
[2023-10-17 17:25:11,255] <launcher> INFO db - db connection established...
[2023-10-17 17:25:12,634] <launcher> ERROR db - Got error while connecting to db: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-256, userName='unifi', source='unifi', password=<hidden>, mechanismProperties=<hidden>}
What am I doing wrong?
Are the docker volumes set correctly?
Am I injecting the secrets in the right way?
I created the unifi db user in the right way?
Thank you in advance for the help.