Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo db #13

Closed
1 task done
Ontrackx opened this issue Sep 17, 2023 · 24 comments
Closed
1 task done

Mongo db #13

Ontrackx opened this issue Sep 17, 2023 · 24 comments
Labels
enhancement New feature or request

Comments

@Ontrackx
Copy link

Is this a new feature request?

  • I have searched the existing issues

Wanted change

Is it possible to get this image with the mongo stuff pre configured? I used the old image with ease. (synolgy nas)
I have trouble setting up the mongo db i have never used it

Reason for change

.

Proposed code change

.

@Ontrackx Ontrackx added the enhancement New feature or request label Sep 17, 2023
@github-actions
Copy link

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

@atais
Copy link

atais commented Sep 17, 2023

Working docker-compose.yml setup with mongo:

---
version: "3"
services:
  unifi:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=unifipwd
      - MONGO_HOST=mongo
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - /yourpc/controller:/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
  mongo:
    image: mongo:4.4.24
    restart: always
    volumes:
      - /yourpc/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - /yourpc/mongo_db:/data/db
      - /yourpc/dbcfg:/data/configdb
    command: 
      mongod --port 27017

and the init-mongo.js content is:

db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "unifipwd", roles: [{role: "readWrite", db: "unifi"}]});
db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "unifipwd", roles: [{role: "readWrite", db: "unifi_stat"}]});

It could be part of readme or there could be a separate document for configurations cookbook or something.
I can make a PR if it works for you

@stefangweichinger
Copy link

crosslinking: https://www.reddit.com/r/Ubiquiti/comments/16e8608/comment/k13f4yv/?utm_source=share&utm_medium=web2x&context=3

my compose-file is similar, but still on older version and with some unnecessary options ...

@thespad
Copy link
Member

thespad commented Sep 18, 2023

We don't want to include a full mongodb compose example because people will just copy/paste it blindly and end up with versions they don't want and missing init files.

@stefangweichinger
Copy link

We don't want to include a full mongodb compose example because people will just copy/paste it blindly and end up with versions they don't want and missing init files.

Understood. Maybe add an explanation ... (?)

@thespad
Copy link
Member

thespad commented Sep 18, 2023

We already have a fairly substantial section on the databse setup https://github.com/linuxserver/docker-unifi-network-application#setting-up-your-external-database. If you think there's specific stuff that needs to be included I'm happy to consider adding it.

@stefangweichinger
Copy link

@thespad yes, the docs are quite good. thanks.

@atais
Copy link

atais commented Sep 18, 2023

We don't want to include a full mongodb compose example because people will just copy/paste it blindly and end up with versions they don't want and missing init files.

Meanwhile me, who copied random snippets from the internet back and forth until it worked and ended up sharing it as "the solution".

@natankeddem
Copy link

We don't want to include a full mongodb compose example because people will just copy/paste it blindly and end up with versions they don't want and missing init files.

It seems like a strange hill to die on. Most of the people migrating to this are going to have no idea how to run Mongo, much less link it to the Unifi Network Application. mongoless usage is less than 1% of the current users on the "Old" image.
image

Providing step by step instructions with actual examples as opposed to the wall of text provided today seems like a good idea. If people aren't initializing the DB you need to make that step one obviously. Half of the issues already posted in this repo are people who can't digest your current documentation. Have a few opinionated examples; nearly no one will care about Mongo versions. The people who do care about versions can figure that out on their own.

@Ontrackx
Copy link
Author

Like me, i do not know what mongo is and what it does. I like the containers to be mostly, add plug and play. For now i use the old image

@thespad
Copy link
Member

thespad commented Sep 20, 2023

It's not a hill to die on, it's a preference based on past experience. Any time we are prescriptive in our instructions users blindly copy/paste them and then while things might work initially they run into problems later. You don't want to know how many users have all their data mounted into /path/to/config.

Half the issues so far have been people not reading the readme, initialising their database with junk data, and then not being able to connect the unifi app to it. There's nothing we can do if people are just going to skip over all of the warnings we've included.

I'll have a conversation internally about how we can improve the readme instructions, but when you're dealing with a user base the breadth of ours it's rarely as straightforward as "just do x".

As an aside, tag pulls are not a good metric. All of our images with additional tags beyond latest have a tiny fraction of pulls from the additional tags because the vast majority of users don't even know they're an option (plus in this specific case that tag has been around for a tiny fraction of the life of the image). Also, pull numbers on registries might as well be randomly generated for how reliable they are a measure of actual image use.

@natankeddem
Copy link

natankeddem commented Sep 20, 2023

I will leave it up to you guys because you have more experience than me with these things. I am just coming in as a user trying to get what you built working. The current documentation is all over the place. It needs to be way more to the point and structured differently. Stop mixing discussion points with instructions on setting up a working environment.

  1. You say this needs an external database; okay sounds good.
  2. The web UI is at ... what? we haven't even set anything up yet why is this here.
  3. Setting up external database; okay here we go...
  4. Okay go to the Mongo container repo and look there...
  5. Okay looks like I need mongo:4.4 maybe or is it 3.6 or should i go for a newer version. I really wish you guys would just decide for me. If you want to have some additional notes at the bottom of the page fine but going into a whole discussion on versioning and how different versions are handled. Lets be honest a small population will care about that. Make this more to the point.
  6. What is this mongo-express thing? Do I need that? No idea.
  7. At this point someone will enter MONGO_INITDB_ROOT_USERNAME: root and MONGO_INITDB_ROOT_PASSWORD: example. Why? Because it was lost in the discussion on versioning.
  8. At some point you get something correct on Mongo and you wonder why didn't they just give you the full example compose instead of the volumes section.
  9. Okay now device adoption section...again why is this here. You haven't even explained how to install the actual application yet.
  10. Now migration from controller; shouldn't this literally be the first thing on this page why is it buried so deep?

An Application Setup area structured more like this with step by step instructions would be easier to follow:

  1. Backup existing Unifi-Controller if needed
  2. Shutdown old Unifi-Controller if running
  3. make file init-mongo.js with content; change user/password if needed:
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "readWrite", db: "MONGO_DBNAME"}]});
db.getSiblingDB("MONGO_DBNAME_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "readWrite", db: "MONGO_DBNAME_stat"}]});
  1. example mongo compose here; change user/password and volume paths as needed:
version: "2.1"
services:
  unifi-app:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-app
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - MONGO_USER=MONGO_USER
      - MONGO_PASS=MONGO_PASS
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - /unifi/app/config:/config
    networks:
      - unifi-network
    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
    
  unifi-db:
    image: mongo:4.4.24
    container_name: unifi-db
    networks:
      - unifi-network
    ports:
      - 27017:27017
    volumes:
      - /unifi/db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - /unifi/db/data:/data/db
      - /unifi/db/config:/data/configdb
 
networks:
  unifi-network:
    driver: bridge
  1. access web gui @ ....
  2. restore backup if required
  3. All other notes/commentary/FAQ below here...

@stefangweichinger
Copy link

stefangweichinger commented Sep 21, 2023

fun fact: same stack 2 times: one in my local environment, one at customer (that's the one in #15): in my stack the admin-user still is there and working.

@bsd43
Copy link

bsd43 commented Sep 25, 2023

An Application Setup area structured more like this with step by step instructions would be easier to follow:

Thank you! I was able to successfully deploy using this without having to separately deal with a Mongo docker-compose.

Suggestions: the harmful risk of someone using MONGO_USER and MONGO_PASS literally via cut&paste is lessened away if you make the mongo database inaccessible to outside the host's container environment. Instead of using "ports", let's use "expose". Another is to use the current working directory for init-mongo.js and other directories. Third is to not lock down to version 4.4.24, but pick up later mongo:4 versions.

So, my working file,

version: "2.1"
services:
  unifi-app:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-app
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - MONGO_USER=MONGO_USER
      - MONGO_PASS=MONGO_PASS
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - ./unifi/app/config:/config
    networks:
      - unifi-network
    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
    
  unifi-db:
    image: mongo:4
    container_name: unifi-db
    networks:
      - unifi-network
    expose:
      - 27017
    volumes:
      - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - ./unifi/db/data:/data/db
      - ./unifi/db/config:/data/configdb
 
networks:
  unifi-network:
    driver: bridge

@stefangweichinger
Copy link

thumbs up ... especially for the "expose"

@thespad
Copy link
Member

thespad commented Sep 26, 2023

expose doesn't really do anything. It's an addendum to the EXPOSE directive in the dockerfile which is effectively just documentation of the ports that the container uses, it doesn't actually change what is and isn't accessible anywhere. There are some external circumstances where it can be relevant, such as with 3rd party tools which use the EXPOSE directive to perform operations (e.g. Traefik's automatic proxying of ports) but they're uncommon.

You shouldn't be exposing your db containers to the host network anyway, unless you have some specific need to access them from elsewhere on your network, or something running natively on the host. You should always use docker networking to keep that traffic isolated.

@natankeddem
Copy link

@thespad this is the sort of discussion I was hoping for here. What are the best practices for this sort of configuration? You are obviously the expert here. You should try to share your knowledge via the documentation. How can this documentation leed users to the most robust outcome in the most efficient way possible? Right now it feels like people are being given just enough rope to hang themselves.

On a side note if you have the bridge network setup between the containers(or the default network) and you don't need access outside of docker you don't need any ports or expose on mongo.

@LinuxServer-CI LinuxServer-CI moved this from Issues to Done in Issue & PR Tracker Sep 26, 2023
@thespad
Copy link
Member

thespad commented Sep 26, 2023

The problem is that a lot of these discussions are around fundamental docker concepts and are well outside the scope of an individual image readme. We can't include first principles instruction in every repo, it's just not practical, there has to be an assumption that users either have, or are capable of obtaining, a basic understanding of how containers work and hang together.

We know that a lot of people are just blindly copy/pasting (or, god help them, clicking the button in Unraid and crossing their fingers), but we just don't have the resources to design our support around that use case, we're a dozen or so volunteers managing 200+ images.

@josephdpurcell
Copy link

I empathize with the struggles. My hope was to find an all-inclusive docker-compose.yml but couldn't find one. After reading some docker compose examples in this thread I was able to cobble together something that worked for me: https://github.com/josephdpurcell/docker-compose-unifi-network-application

I found @natankeddem's comment here #13 (comment) especially helpful! Thank you!

Perhaps this issue could be re-opened and reframed as a documentation request for a docker compose that includes the mongo service?

@javito1081
Copy link

javito1081 commented Nov 10, 2023

I will leave it up to you guys because you have more experience than me with these things. I am just coming in as a user trying to get what you built working. The current documentation is all over the place. It needs to be way more to the point and structured differently. Stop mixing discussion points with instructions on setting up a working environment.

  1. You say this needs an external database; okay sounds good.
  2. The web UI is at ... what? we haven't even set anything up yet why is this here.
  3. Setting up external database; okay here we go...
  4. Okay go to the Mongo container repo and look there...
  5. Okay looks like I need mongo:4.4 maybe or is it 3.6 or should i go for a newer version. I really wish you guys would just decide for me. If you want to have some additional notes at the bottom of the page fine but going into a whole discussion on versioning and how different versions are handled. Lets be honest a small population will care about that. Make this more to the point.
  6. What is this mongo-express thing? Do I need that? No idea.
  7. At this point someone will enter MONGO_INITDB_ROOT_USERNAME: root and MONGO_INITDB_ROOT_PASSWORD: example. Why? Because it was lost in the discussion on versioning.
  8. At some point you get something correct on Mongo and you wonder why didn't they just give you the full example compose instead of the volumes section.
  9. Okay now device adoption section...again why is this here. You haven't even explained how to install the actual application yet.
  10. Now migration from controller; shouldn't this literally be the first thing on this page why is it buried so deep?

An Application Setup area structured more like this with step by step instructions would be easier to follow:

  1. Backup existing Unifi-Controller if needed
  2. Shutdown old Unifi-Controller if running
  3. make file init-mongo.js with content; change user/password if needed:
db.getSiblingDB("MONGO_DBNAME").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "readWrite", db: "MONGO_DBNAME"}]});
db.getSiblingDB("MONGO_DBNAME_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "readWrite", db: "MONGO_DBNAME_stat"}]});
  1. example mongo compose here; change user/password and volume paths as needed:
version: "2.1"
services:
  unifi-app:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-app
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - MONGO_USER=MONGO_USER
      - MONGO_PASS=MONGO_PASS
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - /unifi/app/config:/config
    networks:
      - unifi-network
    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
    
  unifi-db:
    image: mongo:4.4.24
    container_name: unifi-db
    networks:
      - unifi-network
    ports:
      - 27017:27017
    volumes:
      - /unifi/db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - /unifi/db/data:/data/db
      - /unifi/db/config:/data/configdb
 
networks:
  unifi-network:
    driver: bridge
  1. access web gui @ ....
  2. restore backup if required
  3. All other notes/commentary/FAQ below here...

I have read all the replys on this post and i still cant find a solution for my issue, i though ok im going to copy and paste exactly these configs and try them on, if they work ill modify them acordinly but no, it doesnt work for me, i keep getting a 404 page as soon as i get into https://myip:8443, what am i doing wrong? :-( my docker-compose.yml looks like this

version: '3.8'
services:
npm:
image: 'jc21/nginx-proxy-manager:latest'
container_name: npm
restart: unless-stopped
ports:
- '80:80'
- '81:81'
- '443:443'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt

unifi-app:
image: 'lscr.io/linuxserver/unifi-network-application:latest'
container_name: unifi-app
depends_on:
- unifi-db
environment:
- PUID=1000
- PGID=1000
- TZ=America/New_York
- MONGO_USER=MONGO_USER
- MONGO_PASS=MONGO_PASS
- MONGO_HOST=unifi-db
- MONGO_PORT=27017
- MONGO_DBNAME=unifi
- MEM_LIMIT=1024 #optional
- MEM_STARTUP=1024 #optional
volumes:
- /unifi/app/config:/config
networks:
- unifi-network
ports:
- 8446:8443
- 3478:3478/udp
- 10001:10001/udp
- 8085:8080
- 1900:1900/udp #optional
- 8843:8843 #optional
- 8880:8880 #optional
- 6789:6789 #optional
- 5514:5514/udp #optional

unifi-db:
image: mongo:4.4.24
container_name: unifi-db
networks:
- unifi-network
ports:
- 27017:27017
volumes:
- /unifi/db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- /unifi/db/data:/data/db
- /unifi/db/config:/data/configdb

networks:
unifi-network:
driver: bridge

and this is the log im getting when i run docker logs

{"t":{"$date":"2023-11-10T19:11:20.096+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn1001","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":"MONGO_USER@unifi"}}
{"t":{"$date":"2023-11-10T19:11:20.096+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn1001","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"MONGO_USER","authenticationDatabase":"unifi","remote":"172.20.0.3:55538","extraInfo":{},"error":"UserNotFound: Could not find user \"MONGO_USER\" for db \"unifi\""}}
{"t":{"$date":"2023-11-10T19:11:20.097+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn1001","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"MONGO_USER","authenticationDatabase":"unifi","remote":"172.20.0.3:55538","extraInfo":{},"error":"UserNotFound: Could not find user \"MONGO_USER\" for db \"unifi\""}}
{"t":{"$date":"2023-11-10T19:11:20.097+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn1001","msg":"Connection ended","attr":{"remote":"172.20.0.3:55538","connectionId":1001,"connectionCount":2}}
{"t":{"$date":"2023-11-10T19:11:20.098+00:00"},"s":"I",  "c":"-",        "id":20883,   "ctx":"conn1000","msg":"Interrupted operation as its client disconnected","attr":{"opId":6801}}
{"t":{"$date":"2023-11-10T19:11:20.098+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn1000","msg":"Connection ended","attr":{"remote":"172.20.0.3:55532","connectionId":100

its telling me the user has not been found, but i created the init-mongo.js exactly as you did it on /unifi/db/init-mongo.js so i dont know whats going on

Edit: i manage to make it work, but i had to login into mongo shell and insert both commands manually to create the users and db, imma figure it out whats going on with the script and then post a proper guide for future users :-)

@javito1081
Copy link

javito1081 commented Nov 12, 2023

Aight, so this is a little guide for someone who has basic to no knoledge of how to use mongo or docker-container, im going to base it following the original guide on the nextcloud-aio github so here we go:

Note: if you are migrating from the previous docker controller, just go to your controller - settings - backups and download ur backup file, then stop/delete your current controller and start this guide

Step 1: Creating Mongo init-mongo.js file

This file should be located where you assign your db folder on your docker-compose.yml or docker run command for this example im going to create a folder in /unifi/db adn after that im going to use my editor to create the file, in my case i love nano, so ill do:

nano /unifi/db/init-mongo.js

in there ill copy the content shown on the github example:

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"}]});

Now, we need to modify 3 fields according to what we want, the fields are MONGO_DBNAME, MONGO_USER, MONGO_PASS and MONGO_DBNAME_stat, remember these fields will have to match on your docker-compose.yml or docker run command, for this example im going to set them up as @natankeddem did on his post but using unifi as dbname instead of MONGO_DBNAME

db.getSiblingDB("unifi").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "unifi"}]});
db.getSiblingDB("unifi_stat").createUser({user: "MONGO_USER", pwd: "MONGO_PASS", roles: [{role: "dbOwner", db: "unifi_stat"}]});

Notice he also changed the role dbOwner for readWrite, both options are fine, this just define the permisions the user have on the database

So, save the file and now its time to create our docker compose file to fire up the mongo and the controller.

Step 2: Create docker compose file for Mongo

For this wer gonna use the sample on github and modify it to our needs and im going to call it mongo.yml

version: "2.1"
services:
  unifi-db:
    image: docker.io/mongo:<version tag>
    container_name: unifi-db
    volumes:
      - /path/to/data:/data/db
      - /path/to/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
    restart: unless-stopped

Note: i added the first part that was missing from the original github guide, for those who havent mess with docker-compose before.

First of all we have to define the image, they say their docker support any version of mongo up to the latest, but the oficial support versions are the ones between 3.6 and 4.4, its up to you for which you wanna choose, but lets asumo wer going to pick the latest one oficially suported, we have to change image: docker.io/mongo:<version tag> for mongo:4.4.24.

Next we change the volumes to the ones we have created at the start of the example, in this case /path/to/ changes for/unifi/db

And now, our mongo.yml will look like this:

version: "2.1"
services:
  unifi-db:
    image: mongo:4.4.24
    container_name: unifi-db
    volumes:
      - /unifi/db/data:/data/db
      - /unifi/db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
    restart: unless-stopped

Step 3: Create docker compose file for the Unifi Controller

For the last step, we need now to create another docker compose file, which im going to call unifi.yml and add the content on the github example:

version: "2.1"
services:
  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=
      - 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:
      - /path/to/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

And wer going to modify it acording to the information we put on our init-mongo.js file and the patch we created for our unifi folder, following once again @natankeddem example

First thing we have to change is the user, for the one we used on init-mongo.js which in this case is MONGO_USER same for pass MONGO_PASS and dbname unifi and finally the volume path which in this example wer gonna name /unifi/app, so the file will end up like this:

version: "2.1"
services:
  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=MONGO_USER
      - MONGO_PASS=MONGO_PASS
      - 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/app/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

Note: if you dont have any other services running on your server, just leave ports as they are, or if u do, or you want to change the ports, lets asumo we want to use another http configuration port for lets say 8085, then we change - 8080:8080 for - 8085:8080, first one is the port on which your container will run for external access, the 2nd one is the one that the application uses internally, so if you also want to change that, you will have to do it on the config file inside the /unifi/app/data:/config folder.

So now we save the file and we should be ready to run our docker.

Step 4: Running the controller and mongo

Now we have everything ready to go, so we just execute the command:

docker-compose -f mongo.yml -f unifi.yml up -d

Then docker will start downloading the images and once they are done they should run without issues, after it says they are running, give it about 30 secs as a first run before trying to access it, because the databases has to be generated and all the config files, so if you get a 404 page at first dont panic, give it a couple of secconds to refresh and should be good to go.

The way to access for the first time should be going into the website https://:8443 asuming your ip is 10.0.0.2 should be https://10.0.0.2:8443.

After that once your on the first page, setup your information and ull be done, also if your migrating from a previous controller you could click on the botton part on the option to import the backup and follow the instructions to finish.

Optional: if you dont want to create diferent docker compose files, you can merge it all into one for example, like this will also be fine:

version: "2.1"
services:
  unifi-app:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-app
    restart: unless-stopped
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Mexico_City
      - MONGO_USER=MONGO_USER
      - MONGO_PASS=MONGO_PASS
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi
      - MEM_LIMIT=1024 #optional
      - MEM_STARTUP=1024 #optional
    volumes:
      - /unifi/app/config:/config
    ports:
      - 8443:8443
      - 3480:3478/udp
      - 10001:10001/udp
      - 8080:8080
      - 1900:1900/udp #optional
      - 8843:8843 #optional
      - 8880:8880 #optional
      - 6789:6789 #optional
      - 5514:5514/udp #optional

  unifi-db:
    image: mongo:4.4.24
    container_name: unifi-db
    ports:
      - 27017:27017
    volumes:
      - /unifi/db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - /unifi/db/data:/data/db
      - /unifi/db/config:/data/configdb

Lets asume we save that configo into a file called unifi-app-db.yml, after that we just run it using the command

docker-compose -f unifi-app-db.yml up -d

Thats it, i hope this guide will help all of those in need to set this up without experience with mongo or docker-compose, i made this guide for internal hosting only, if you want to be able to access your controller from the internet, dont forget to open the ports on your router 👍

@rightsaidfred99
Copy link

rightsaidfred99 commented Dec 24, 2023

Doesn't work on a Pi4

version: "2.1"
services:
  unifi-app:
    image: lscr.io/linuxserver/unifi-network-application:arm64v8-latest
    container_name: unifi-app
    depends_on:
      - unifi-db
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Australia/Sydney
      - MONGO_USER=admin
      - MONGO_PASS=pass
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi
    volumes:
      - /home/pi/docker/unifinetwork/app/config:/config
    networks:
      - unifi-network
    ports:
      - 8443:8443
      - 3478:3478/udp
      - 10001:10001/udp
      - 8080:8080
    
  unifi-db:
    image: mongo:4
    platform: linux/arm64
    container_name: unifi-db
    networks:
      - unifi-network
    expose:
      - 27017
    volumes:
      - /home/pi/docker/unifinetwork/db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - /home/pi/docker/unifinetwork/db/data:/data/db
      - /home/pi/docker/unifinetwork/db/config:/data/configdb
 
networks:
  unifi-network:
    driver: bridge

@lennynilsson
Copy link

For the next person having this issue. This is how I wrote the init script: #43 (comment)

@camaz
Copy link

camaz commented Jan 10, 2024

@rightsaidfred99, I have it running on on an Raspberry Pi 4 by pulling image version mongo:4.4.13. This is an earlier version than you get with mongo:4 and I believe the last version which officially supports the Raspberry Pi.

There are unofficial builds of more recent Mongodb for the Raspberry Pi here, but I haven't tested those..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests