Closed 1shindes closed 2 months ago
Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.
My guess is, either your init-mongo.js
is incorrect, or your mongodb already had some data in there (or you included the user/db vars the first time).
Most of our team members use unifi. We all followed the readme and I assure you it works.
@aptalca thanks for your reply!
Mу whole init-mongo.js
is just these 2 strings from Readme:
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}]});
db.getSiblingDB("MONGO_DBNAME_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME_stat"}]});
As I pointed out at issue description, I'm using clean Ubuntu install and building containers in a new directory from zero. If I make any changes to docker-compose config, I delete mapped volumes, execute docker container prune
and only after that I build a new containers for app and mongo.
By
or you included the user/db vars the first time
you mean what?
@1shindes had this problem as well as I screwed it up the first time around. Make sure to change the values inside of the init-mongo.js
file to the values you want for example:
db.getSiblingDB("unifi").createUser({user: "unifi-user", pwd: "password1234", roles: [{role: "dbOwner", db: "unifi"}]});
db.getSiblingDB("unifi_stat").createUser({user: "unifi-user", pwd: "password1234", roles: [{role: "dbOwner", db: "unifi_stat"}]});
Also if you did mess up the first time around I would prune any volumes that are not used with docker volumes prune
@kylemello Thanks! By the time I received your reply I've found it myself.
The problem is that I treat init-mongo.js
literally, being confused with the MONGO_USER and MONGO_PASS, which I thought I can pass to init script as envs. So I use .env
with a lot of variables - best practices and all that. This won't work in this setup!
To be short, that's the correct set of config files. All you need is to docker-compose up -d
That's it! No Dockerfile
, no .env
. MONGO_USER and MONGO_PASS values must be hardcoded and if you change them in .yml
file - you must change them in .js
file correspondingly.
So in other words, you did not follow the readme precisely as the readme states Being sure to replace the placeholders with the same values you supplied to the Unifi container
.
Glad it's solved.
It's worth noting that if something gets messed up with the database initialization and you're trying to recreate the containers you must clear out BOTH the mongodb data AND the unifi config folders.
I initially didn't escape special characters in the password. I figured that part out pretty quickly and corrected it but only cleared out the mongodb data folder before recreating the containers thinking the unifi config would read an updated password specified in the compose file. That stymied me for a bit because the unifi app was still failing to authorize against the mongodb instance. I finally realized I should try clearing out everything before recreating the containers and that did the trick.
Might be worth adding a small blurb to the README about making sure absolutely all the persistent volumes are cleared out if you are trying to start over after a failed initialization.
Maybe I just missed it in the docs, but I had the exact same issue because I used a password longer than 32 chars.
/### Is there an existing issue for this?
Current Behavior
Trying to start me the docker-unifi-network-application following README.md precisely using docker-compose and the
following config:
```yaml --- services: unifi-db: hostname: unifi-db container_name: unifi-db image: 'mongo:7.0.5' volumes: - ./unifi-db/data:/data/db - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro ports: - 27017:27017 restart: unless-stopped unifi-network-application: image: lscr.io/linuxserver/unifi-network-application:latest container_name: unifi-network-application environment: - PUID=1000 - PGID=1000 - TZ=Etc/UTC - MONGO_USER=unifi - MONGO_PASS=inifipass - MONGO_HOST=unifi-db - MONGO_PORT=27017 - MONGO_DBNAME=unifi # - MEM_LIMIT=1024 #optional # - MEM_STARTUP=1024 #optional # - MONGO_TLS= #optional # - MONGO_AUTHSOURCE= #optional volumes: - ./unifi-network/data:/config 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 depends_on: - unifi-db ```Database wasn't initialized
``` root@unifi-db:/# mongosh Current Mongosh Log ID: 6616aab15abee8a0c8e10dd5 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.4 Using MongoDB: 7.0.5 Using Mongosh: 2.1.4 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy). You can opt-out by running the disableTelemetry() command. ------ The server generated these startup warnings when booting 2024-04-10T15:03:17.974+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2024-04-10T15:03:19.924+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted 2024-04-10T15:03:19.925+00:00: vm.max_map_count is too low ------ test> show databases admin 100.00 KiB config 12.00 KiB local 72.00 KiB test> use admin switched to db admin admin> show users [] admin> quit ````Hence the application doesn't start up properly.
I can create mongo-express container additionally, manually create unifi user, unifi/unifi_stat database etc., restart the application container only and then, if did it all right, succeed. But this means that the instructions from README are not correct for my system setup, at least, and maybe they have to be updated.
Is it even possible to, with proper yaml file, start up docker-unifi-network-application from scratch or it's just me doing all wrong?
Expected Behavior
App should be working
Steps To Reproduce
Environment
CPU architecture
x86-64
Docker creation
as per yaml config
Container logs