ITS-Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Unifi Controller Docker with external MongoDB container

    Scheduled Pinned Locked Moved IT-Stuff
    1 Posts 1 Posters 227 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      admin
      last edited by admin

      Here I describe how you connect the Unifi Controller to external Database.

      At first you need the MongoDB Container.

      create docker-compose.yml in folder mongodb where you want it:

      services:
        mongo:
          image: 'mongo:4.4'
          restart: unless-stopped
          ports:
            - '27017:27017'
          environment:
            MONGO_INITDB_ROOT_USERNAME: test
            MONGO_INITDB_ROOT_PASSWORD: password
            MONGO_INITDB_DATABASE: test
          volumes:
            - mongo-data:/data/db
      
      volumes:
        mongo-data:
      

      Then you need to create User for Unifi Controller like this:

      use unifi
      db.createUser(
        {
          user: "unifi",
          pwd: "password",  // or cleartext password
          roles: [
             { role: "readWrite", db:"admin" } ,
             { role: "readWrite", db:"unifi" } ,
             { role: "readWrite", db:"unifi_stat" }
          ]
        }
      )
      
      

      Now we can another folder called unifi and also create the docker-compose.yml

      version: '2.3'
      services:
        controller:
          image: "jacobalberty/unifi:latest"
          container_name: unifi_controller
          init: true
          restart: always
          volumes:
            - dir:/unifi
            - data:/unifi/data
            - log:/unifi/log
            - cert:/unifi/cert
            - init:/unifi/init.d
            - run:/var/run/unifi
            # Mount local folder for backups and autobackups
            - ./backup:/unifi/data/backup
          user: unifi
          sysctls:
            net.ipv4.ip_unprivileged_port_start: 0
          environment:
            # DB_URI: mongodb://mongo/unifi
            #STATDB_URI: mongodb://mongo/unifi_stat
            DB_URI: mongodb://unifi:password@89.58.43.67:27017/unifi?authSource=unifi
            STATDB_URI: mongodb://unifi:password@89.58.43.67:27017/unifi_stat?authSource=unifi
            DB_NAME: unifi
          ports:
            - "3478:3478/udp" # STUN
            - "5514:5514/tcp" # Remote Logging 
            - "6789:6789/tcp" # Speed test
            - "8080:8080/tcp" # Device/ controller comm.
            - "8443:8443/tcp" # Controller GUI/API as seen in a web browser
            - "8880:8880/tcp" # HTTP portal redirection
            - "8843:8843/tcp" # HTTPS portal redirection
            - "10001:10001/udp" # AP discovery
        logs:
          image: bash
          container_name: unifi_logs
          depends_on:
            - controller
          command: bash -c 'tail -F /unifi/log/*.log'
          restart: always
          volumes:
            - log:/unifi/log
      
      volumes:
        data:
        log:
        cert:
        init:
        dir:
        run:
      
      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post
      Powered by NodeBB | Contributors