Closed h4ng3r closed 3 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.
I'm having 404 issues when using macvlan networking and no port forwarding:
mac_address: 8A:A2:60:29:EE:00
networks:
macvlan0:
ipv4_address: 192.168.1.5
https://192.168.1.5:8443/ opens with HTTP Status 404 – Not Found
But works when using:
ports:
- 8443:8443
and accessing with https://docker-host-ip:8443
I see the same issue, and I think it might have something to do with the database.
Have you looked in/opt/unifi-network-application/logs/server.log
?
In my own server.log
I see the following error (formatted for clarity):
[2023-09-13 21:51:47,352] <launcher> WARN AnnotationConfigWebApplicationContext
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'adoptInfoService' defined in com.ubnt.service.adopt.AdoptSpringContext:
Unsatisfied dependency expressed through method 'adoptInfoService' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'wirelessAdoptionService' defined in com.ubnt.service.devmgr.wireless.WirelessDeviceSpringContext: Unsatisfied dependency expressed through method 'wirelessAdoptionService' parameter 1;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'deviceManager' defined in com.ubnt.service.devmgr.DeviceManagerSpringContext: Unsatisfied dependency expressed through method 'deviceManager' parameter 7;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'siteManager' defined in com.ubnt.service.AppContext: Unsatisfied dependency expressed through method 'siteManager' parameter 5;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'statService' defined in com.ubnt.service.AppContext: Invocation of init method failed;
nested exception is com.mongodb.MongoCommandException:
Command failed with error 13 (Unauthorized): 'not authorized on unifi_stat to execute command
{ listCollections: 1,
cursor: {},
nameOnly: true,
$db: "unifi_stat",
lsid: { id: UUID("1fc0d5a9-a851-4625-912b-e84a4365df31") }
}'
on server db:27017.
The full response is
{"ok": 0.0,
"errmsg": "not authorized on unifi_stat to execute command { listCollections: 1, cursor: {}, nameOnly: true, $db: \"unifi_stat\", lsid: { id: UUID(\"1fc0d5a9-a851-4625-912b-e84a4365df31\") } }",
"code": 13,
"codeName": "Unauthorized"}
Which is pretty weird, because I do have a unifi
user on the database unifi
and unifi_stat
, and if I try to connect through that, I am able to run show collections
(which I presume is equivalent to "listCollections").
If the error is different I'll open a separate issue.
On my server.log
I have a bunch of connection sucessfull messages. I've double checked de mongo db user and password and it works.
Right, I did a fresh deploy and it now works for me too (I had used MONGO_INITDB_ROOT_USERNAME
and MONGO_INITDB_ROOT_PASSWORD
instead of the init-mongo.js
method). Sorry about the noise.
@h4ng3r Try going onto your Mongo DB container and connecting using the connection string in your logs. If that works it at least rules out a connection problem. I was getting a bunch of db connection established
but didn't get db connected
which should come after it. In my case I had network connection issues between containers.
Hi, i have the same result in http error 404, when opening the website. My mongodb server has version 4.4.24. I Server.log i see, that a connection to mongodb cannot be established due to login credential issues. So i can rule out network problems.
Server.log
[2023-09-16 16:14:01,461] <launcher> INFO db - db connection established...
[2023-09-16 16:14:01,976] <launcher> ERROR db - Got error while connecting to db: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='unifictrl', source='unifictrl', password=<hidden>, mechanismProperties=<hidden>}
On mongodb server i can login and list collections.
Here is the output of "show users":
"_id" : "admin.unifictrl", "userId" : UUID("8b5d48af-2f40-43dc-876e-abb312a88909"), "user" : "unifictrl", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "unifictrl" }, { "role" : "readWrite", "db" : "unifictrl_stat" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
Is this correct?
Stumbled into this issue too. I had the same thing @mcassaniti faced where I had the hostname for the mongodb wrong.
I put everything into a docker-compose.yml
file:
---
version: "3.4"
services:
mongodb:
image: mongo:4.4.24
container_name: unifi-mongodb
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- ~/.unifi/mongo:/data/db
ports:
- 27017:27017
unifi-network-application:
depends_on:
mongodb:
condition: service_healthy
image: lscr.io/linuxserver/unifi-network-application:latest
container_name: unifi-network-application
environment:
- PUID=1000
- PGID=1000
- TZ=Australia/Brisbane
- MEM_LIMIT=1024 #optional
- MEM_STARTUP=1024 #optional
- MONGO_USER=unifi
- MONGO_PASS=replaceme
- MONGO_HOST=mongodb
- MONGO_PORT=27017
- MONGO_DBNAME=unifi
volumes:
- ~/.unifi/config:/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
Key to note is the env var MONGO_HOST
is referencing the docker-compose service mongodb
. I previously had localhost
there because I was just copy+pasting without thinking what I was doing :sweat_smile:
And the init-mongo.js
being:
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "readWrite", db: "unifi"}]});
db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "readWrite", db: "unifi_stat"}]});
Pretty much exactly as the example in the Readme.
Hope this helps in any way.
Hope this helps in any way.
Was having the same issue, forgot to expose my db port but seeing your config helped. Thanks for the assist. Db health check did not work, anything special to get that working?
For me, that config above as is is what I'm running successfully now (replacing the password with an actual password).
Hi,
my Problem is partialy solved.
Something went wrong with my password in mongodb for user "unifictrl".
In unify-network-application "server.log" i always saw this lines:
Connecting to mongodb://unifictrl:~MONGO_PASS~@<MONGODB_IP-ADDRESS>:27017/unifictrl
When i look in mongodb "show log" i saw this lines:
{"t":{"$date":"2023-09-18T17:42:05.893+02:00"},"s":"I", "c":"ACCESS", "id":20249, "ctx":"conn15863","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"unifictrl","authenticationDatabase":"unifictrl","remote":"<UNIFI_NETWORK_APPLICATION_IP_ADDRESS>:41276","extraInfo":{},"error":"AuthenticationFailed: SCRAM authentication failed, storedKey mismatch"}}
My Solution was to delete the mongodb-container and start a new instance.
Now i get this lines in "server.log"
2023-09-18 17:56:05,181] <launcher> INFO db - waiting for db connection...
[2023-09-18 17:56:05,683] <launcher> INFO db - Connecting to mongodb://unifictrl:<MY_PASSWORD>@<MONGODB_IP-ADDRESS>:27017/unifictrl
[2023-09-18 17:56:06,149] <launcher> INFO db - db connection established...
[2023-09-18 17:56:06,385] <launcher> INFO db - db connected (v4.4.24@mongodb://unifictrl:<MY_PASSWORD>@<MONGODB_IP-ADDRESS>:27017/unifictrl)
[2023-09-18 17:56:25,811] <launcher> INFO db - Database service initialized...
Now I'm still not able to browse to https://.... not authorized on unifictrl_stat to execute command ....
Newer MongoDB requires ?authSource=admin
in DB_URI. Try adding it to system.properties
and it should work.
Thank you ym, that was the solution. I created my mongodb user in "admin" Database, and authorized it with roles to "unifictrl" and "unifictrl_stat" databases. So my authentication database is "admin" and it's important to connect to mongodb with the string "?authSource=admin". I'm very new to mongodb, but now it runs.
Also having this issue. After breaking my whole head I found this issue with this thread. As @smdmitry mentioned here he also has a 404 error when using macvlan.
My compose:
---
version: "3.7"
services:
unifi-controller:
image: lscr.io/linuxserver/unifi-network-application:latest
container_name: unifi-network-application
depends_on:
- mongodb
ports:
- 8880:8880 #HTTP port #optional
- 8443:8443 #HTTPS port
- 3478:3478/udp
- 10001:10001/udp
- 8080:8080
- 1901:1900/udp #optional #Changed external port for testing with macvlan vs bridge
- 8843:8843 #optional
- 6789:6789 #optional
- 5514:5514/udp #optional
networks:
service:
#net:
# ipv4_address: 10.0.0.253
domainname: appoxo.home
volumes:
- ${DIR_LOCALTIME}:/etc/localtime:ro
- /opt/docker/container/unifi/config:/config
environment:
PUID: 1005
PGID: 1004
TZ: ${TZ}
MONGO_USER: ${UNIFI_USER}
MONGO_PASS: ${UNIFI_PASS}
MONGO_HOST: mongodb
MONGO_PORT: 27017
MONGO_DBNAME: unifi-db
MEM_LIMIT: 2048 #optional
MEM_STARTUP: 2048 #optional
labels:
com.centurylinklabs.watchtower.enable: true
com.centurylinklabs.watchtower.scope: unifiScope
restart: unless-stopped
#---------------------------------------------------------------------------------------------------------
mongodb:
image: mongo:4.4
container_name: mongodb
expose:
- 27017
networks:
- service
volumes:
- /opt/docker/container/mongodb/data/db:/data/db
- /opt/docker/container/mongodb/data/configdb:/data/configdb
#- /opt/docker/container/mongodb/data/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
#environment:
#NOTICE: Uncommented due to being used only once at setup!
#MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
#MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
healthcheck:
test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 10s
retries: 5
start_period: 20s
restart: always
#---------------------------------------------------------------------------------------------------------
mongo-express:
image: mongo-express
container_name: mongoexpress
depends_on:
- mongodb
ports:
- 8081:8081
networks:
- service
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: #${MONGO_INITDB_ROOT_USERNAME}
ME_CONFIG_MONGODB_ADMINPASSWORD: #${MONGO_INITDB_ROOT_PASSWORD}
ME_CONFIG_MONGODB_URL: mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@mongodb:27017/
labels:
# Watchtower:
com.centurylinklabs.watchtower.enable: true
com.centurylinklabs.watchtower.scope: unifiScope
restart: unless-stopped
As soon as I used the bridge "service" network and commented out the macvlan "net" network it worked. With the "net" network I got the 404 issue.
Seems like this container needs work regarding this driver?
Edit: Nevermind. If first setup with the bridge network and then changed back to the macvlan network (or using both in my case), I could access the container via it's ip.
networks:
service:
net:
ipv4_address: 10.0.0.253
I had the same issue of the webserver not being reachable. The terminal showed a rejected connection multiple times a second, due to the user and database not existing. Hidden further up the in the flood of messages was an exit code (-3) unable to load init-mongo.js. The resolution for me was to set the permissions for init-mongo.js
so it was executable by the UID or GID.
Could be worth mentioning this in the install notes. Hopefully this helps someone else.
Stumbled into this issue too. I had the same thing @mcassaniti faced where I had the hostname for the mongodb wrong. I put everything into a
docker-compose.yml
file:--- version: "3.4" services: mongodb: image: mongo:4.4.24 container_name: unifi-mongodb volumes: - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro - ~/.unifi/mongo:/data/db ports: - 27017:27017 unifi-network-application: depends_on: mongodb: condition: service_healthy image: lscr.io/linuxserver/unifi-network-application:latest container_name: unifi-network-application environment: - PUID=1000 - PGID=1000 - TZ=Australia/Brisbane - MEM_LIMIT=1024 #optional - MEM_STARTUP=1024 #optional - MONGO_USER=unifi - MONGO_PASS=replaceme - MONGO_HOST=mongodb - MONGO_PORT=27017 - MONGO_DBNAME=unifi volumes: - ~/.unifi/config:/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
Key to note is the env var
MONGO_HOST
is referencing the docker-compose servicemongodb
. I previously hadlocalhost
there because I was just copy+pasting without thinking what I was doing 😅And the
init-mongo.js
being:db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "readWrite", db: "unifi"}]}); db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "readWrite", db: "unifi_stat"}]});
Pretty much exactly as the example in the Readme.
Hope this helps in any way.
This worked perfectly for me, whereas using the readme setup kept giving me the 404 issues. Thanks very much for this.
I just spent an hour on a similar issue until I noticed "Only evaluated on first run." next to the MONGO_PASS environment variable. Deleting the files in the /config directory and starting over solved my issues. I had started the container with the wrong password the first time.
For me the 404 error was caused by the unifi app failing to connect to the mongo database. The failure was caused by special characters in the password. With these removed everything worked fine.
I was hit by the same issue on a synology NAS with docker installed. Username & PW were correct but it got stuck endless
db connection established... db connection established... db connection established... db connection established...
messages. Solution was to not use the default bridge network of docker but attach both containers into a custom bridge network. Apparently the default bridge network, although inter-container-connectivity was enabled, does not allow containers to communicate properly.
here is my final docker-compose.yaml file:
version: "3.4"
services:
unifi-network-application:
depends_on:
unifi-mongodb:
condition: service_healthy
image: lscr.io/linuxserver/unifi-network-application:latest
container_name: unifi-network-application
hostname: unifi-network-application
environment:
- PUID=1000
- PGID=100
- MONGO_USER=unifi
- MONGO_PASS=ReplaceMe
- MONGO_HOST=unifi-mongodb
- MONGO_PORT=27017
- MONGO_DBNAME=unifi
volumes:
- /volume1/LocalPath-toReplace:/config
ports:
- 8443:8443
- 3478:3478/udp
- 10001:10001/udp
- 8080:8080
- 8843:8843 #optional
- 8880:8880 #optional
- 6789:6789 #optional
- 5514:5514/udp #optional
network_mode: unifi
restart: unless-stopped
unifi-mongodb:
image: mongo:4.4.24
container_name: unifi-mongodb
hostname: unifi-mongodb
volumes:
- /volume1/LocalPath-toReplace/init/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- /volume1/LocalPath-toReplace/data:/data/db
restart: unless-stopped
network_mode: unifi
healthcheck:
test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 10s
retries: 5
start_period: 20s
PS: You do not need to expose the port in the mongoDB container if both are running in the same bridged network. From a security point of view this is anyway not recommended, as exposing the port will expose it automatically outside docker...
@pilmarCH
You do not need to expose the port in the mongoDB container if both are running in the same bridged network. From a security point of view this is anyway not recommended, as exposing the port will expose it automatically outside docker...
If you mean the compose declaration ports:
yes.
If you mean the expose:
declaration: Not really
Source: Docker.com Compose docs
Expose ports without publishing them to the host machine - they'll only be accessible to linked services. Only the internal port can be specified.
Which is really only optimal for communication between unifi and mongodb...
@pilmarCH
You do not need to expose the port in the mongoDB container if both are running in the same bridged network. From a security point of view this is anyway not recommended, as exposing the port will expose it automatically outside docker...
If you mean the compose declaration
ports:
yes.If you mean the
expose:
declaration: Not really Source: Docker.com Compose docsExpose ports without publishing them to the host machine - they'll only be accessible to linked services. Only the internal port can be specified.
Which is really only optimal for communication between unifi and mongodb...
I meant with ports: ,thanks for the further explenation.
For me the only issue was the line of code given in the readme:
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}, {role: "dbOwner", db: "MONGO_DBNAME_stat"}]});
Of course with my own variables in it:
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "dbOwner", db: "unifi"}, {role: "dbOwner", db: "unifi_stat"}]});
When I replaced it with the two lines below, everything worked as expected. The Readme code example is not working on a mongodb version 4.4, while the below code does.
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "dbOwner", db: "unifi"}]});
db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "replaceme", roles: [{role: "dbOwner", db: "unifi_stat"}]});
Hi, all described solutions doesnt work for me. The authSource in system.properties is not admin, it´s unifi! With the following modifications it runs fine :)
docker-compose.yml
unifi-db: image: mongo:4.4.24 container_name: unifi-db restart: always hostname: unifi-db volumes: - unifi-db:/data/db - unifi-dbcfg:/data/configdb - ./unifi/mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro unifi: build: context: unifi image: unifi container_name: unifi hostname: unifi environment: - PUID=1000 - PGID=1000 - TZ=Etc/UTC - MONGO_USER=unifi - MONGO_PASS=unifipwd - MONGO_HOST=unifi-db - MONGO_PORT=27017 - MONGO_DBNAME=unifi - MEM_LIMIT=1024 #optional - MEM_STARTUP=1024 #optional volumes: - unifi:/config depends_on: - unifi-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 volumes: unifi-db: unifi-dbcfg: unifi: name: unifi-config driver_opts: type: none device: /srv/unifi-config #NOTE needs full path (~ doesn't work) o: bind labels: com.volumes.description: "Volume for config of unifi controller"
file unifi/system.properties
db.mongo.local=false db.mongo.uri=mongodb://~MONGO_USER~:~MONGO_PASS~@~MONGO_HOST~:~MONGO_PORT~/~MONGO_DBNAME~?tls=~MONGO_TLS~&authSource=unifi statdb.mongo.uri=mongodb://~MONGO_USER~:~MONGO_PASS~@~MONGO_HOST~:~MONGO_PORT~/~MONGO_DBNAME~_stat?tls=~MONGO_TLS~&authSource=unifi unifi.db.name=~MONGO_DBNAME~
file unifi/mongo/init-mongo.js
db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "unifipwd", roles: [{role: "dbOwner", db: "unifi"}]}); db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "unifipwd", roles: [{role: "dbOwner", db: "unifi_stat"}]});
file unifi/Dockerfile
FROM ghcr.io/linuxserver/lspipepr-unifi-network-application:7.5.176-pkg-22c0bf17-dev-874e2dfe0459454c38d5695bd67361d9eb59e6a9-pr-21 COPY system.properties /defaults/
From what I can gather, the README step
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "MONGO_DBNAME"}, {role: "dbOwner", db: "MONGO_DBNAME_stat"}]});
will create a user in the MONGO_DBNAME
database with dbOwner
role for for both MONGO_DBNAME
and MONGO_DBNAME_stat
. In order for that to work the authSource
in newer versions would then need to be set to MONGO_DBNAME
.
Or if you're using something like Atlas then the users would be created in the admin
database and you'd need to use admin
as authSource
.
I finally got it working too, with help of the suggestions mentioned above:
init-mongo.js
with the correct permissionsDo a tail -f
on your Unifi logs/server.log
, if you keep seeing lines with only db connection established...
, then you're still not connected. Rebuild and start with a clean set up and make sure you have that separate network and the right settings in that init-mongo.js.
I had the 404 issue as well and I found out my problem was that my password for mongo was too complicated. It had $
in the password. I changed my password to have no symbols, only characters. After doing that and clearing out all the data everything started up correctly.
Was coming in to say this. Since the user and password for mongodb are used in a url string in format http://user:pass@bd, if you have multiple of the reserved net character like @$? or many other, it will failed. Remove special char and it should work.
The readme lists the url encode requirement for the password: https://github.com/linuxserver/docker-unifi-network-application#parameters
I see a successful db connection in my logs, should I assume the error lies somewhere else for me?
[2023-11-24 21:23:38,789] <launcher> INFO system - *** Running for the first time, creating identity ***
[2023-11-24 21:23:38,794] <launcher> INFO system - UUID: 2fa55025-df02-41bc-a5c9-da8b299105a5
[2023-11-24 21:23:38,873] <launcher> INFO system - Reporter UUID: f40774b6-e960-4e8b-b368-06c08dd8a95f
[2023-11-24 21:23:44,670] <launcher> INFO tomcat - Adding basic REST API support during the startup
[2023-11-24 21:23:47,711] <launcher> INFO system - Tomcat startup took 5418ms
[2023-11-24 21:23:48,316] <launcher> INFO tomcat - Adding basic REST API support during the startup
[2023-11-24 21:23:59,669] <launcher> INFO db - Starting database service initialization...
[2023-11-24 21:23:59,670] <launcher> INFO db - waiting for db connection...
[2023-11-24 21:24:00,171] <launcher> INFO db - Connecting to mongodb://unifi:unifi@mongodb-unifi:27017/unifi
[2023-11-24 21:24:00,447] <launcher> INFO db - db connection established...
[2023-11-24 21:24:00,641] <launcher> INFO db - db connected (v4.4.25@mongodb://unifi:unifi@mongodb-unifi:27017/unifi)
Well, it seems latest version, at least for me, give me same error as you sdebruyn. All my ap are in standalone mode and cannot reach unifi controler.
BTW, watchout, the log you posted show your user/pass plaint ext of the mongodb. It seems for me, it stopped working yesterday since I have autobackup everyday until yesterday
edit: just tried reverting all the way to 7.5 and still getting the same tomcat error 404 not found and the controler is not working anymore...
I think I found the problem on my end but I don't know how to solved it. My mongdo is in my custom-network while unifi network app is under eth0 macvlan. If I'm into the unifi app, I cannot ping my server but I can reach anything else on my network. Host access to network is enabled.
edit: Ok so I fixed it on my end. I don't know why but host access to custom network stopped working. I had to stop my docker, disable and enabled back the access then start my docker.
@sdebruyn: verify that from the console inside your unifi container, you can ping mongodb-unifi. On my end, I had to use the ip instead
Sorry for not coming back to this, but it ended up working fine for me. The initial startup just took about 10min.
The mongo uri uses the same authSource in system.properties
because there's only only one MONGO_AUTHSOURCE
environment variable, so it is better to create user like that below and set MONGO_AUTHSOURCE=unifi
then it will work fine.
db.getSiblingDB("unifi").createUser(
{
user: 'unifi',
pwd: 'unifi',
roles:
[
{
role: 'dbOwner',
db: 'unifi'
}, {
role: 'dbOwner',
db: 'unifi_stat'
}
]
}
)
For those looking for a cleaner solution if you pass the mongo environment variables to your mongodb container you can use them in your init-mongo.js
file like this:
db.getSiblingDB(_getEnv('MONGO_DBNAME')).createUser({
user: _getEnv('MONGO_USER'),
pwd: _getEnv('MONGO_PASS'),
roles: [{
role: "dbOwner",
db: _getEnv('MONGO_DBNAME')
},
{
role: "dbOwner",
db: _getEnv('MONGO_DBNAME') + "_stat"
}]
});
Debugging these startup 404 issues would be much easier if /usr/lib/unifi/logs/server.log
was piped to the container stdout.
I would say since this file contain clear text user and password for database wrong idea. Also, there's 7 other logs you might need to look depending on the problem.
@sdebruyn , could you share your working config?
Thanks
I'm not @sdebruyn , but here is my working config.
Should work as-is, no placeholders to fill in unless you want to change the database credentials.
docker-compose.yml
---
version: "3.4"
services:
unifi-network-application:
image: lscr.io/linuxserver/unifi-network-application:8.0.26-ls24
container_name: unifi-network-application
environment:
- PUID=1000
- PGID=1000
- TZ=Australia/Melbourne
- MONGO_USER=unifi
- MONGO_PASS=unifi
- 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:
- ./data/unifi/config:/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
unifi-db:
image: docker.io/mongo:4.4
container_name: unifi-db
environment:
- MONGO_DBNAME=unifi
- MONGO_USER=unifi
- MONGO_PASS=unifi
volumes:
- ./data/mongo/data/db:/data/db
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
restart: unless-stopped
init-mongo.js
db.getSiblingDB(_getEnv('MONGO_DBNAME')).createUser({
user: _getEnv('MONGO_USER'),
pwd: _getEnv('MONGO_PASS'),
roles: [{
role: "dbOwner",
db: _getEnv('MONGO_DBNAME')
},
{
role: "dbOwner",
db: _getEnv('MONGO_DBNAME') + "_stat"
}]
});
And here's mine, but do take into account my first startup took 15min. It's very fast and responsive after that.
networks:
default:
unifi:
services:
mongodb-unifi:
container_name: mongodb-unifi
network_mode: bridge
environment:
- TZ=Europe/Brussels
networks:
- unifi
- default
ports:
- 17017:27017/tcp
expose:
- 27017
image: mongo:4.4
restart: unless-stopped
volumes:
- /volume1/docker/unifi23/mongodb-init.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- /volume1/docker/unifi23/mongodb:/data/db
unifi-network-application:
container_name: unifi-network-application
network_mode: bridge
environment:
- TZ=Europe/Brussels
- MONGO_USER=redacted
- MONGO_PASS=redacted
- MONGO_DBNAME=redacted
- MONGO_HOST=mongodb-unifi
- MONGO_PORT=27017
image: linuxserver/unifi-network-application:8.0.24
ports:
- 10001:10001/udp # AP discovery
- 3478:3478/udp # STUN
- 5514:5514/udp # remote syslog capture
- 6789:6789/tcp # mobile throughput measurement
- 8080:8080/tcp # device and controller communication
- 8443:8443/tcp # web admin
- 8843:8843/tcp # guest portal
- 8880:8880/tcp # captive portal
restart: unless-stopped
depends_on:
- mongodb-unifi
networks:
- unifi
- default
volumes:
- /volume1/docker/unifi23/unifi-network-application:/config
Thank you for sharing your configurations! It helped me find the missing element in mine and resolve my issue
This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.
This issue is locked due to inactivity
Is there an existing issue for this?
Current Behavior
When I try to access the Unifi website it shows 404 error.
Expected Behavior
To the see the Controller / Application website.
Steps To Reproduce
Environment
Container logs