Home Unifi Controller in a container
Post
Cancel

Unifi Controller in a container

Notes for myself to run Unifi controller (and particularly MongoDB) in containers.

Following Unifi Network Application

  • Create /opt/mongodb/docker-compose.yml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
      version: "3"
    
      services:
        unifi-db:
          image: mongodb/mongodb-community-server:4.4.21-ubi8
          container_name: unifi-db
          volumes:
            - data:/data/db
            - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
          restart: unless-stopped
    
      volumes:
        data:
          driver: local
          driver_opts:
            type: none
            device: ./data
            o: bind
    

    and /opt/mongodb/init-mongo.js (pick your own password and use it in unifi docker-compose)

    1
    2
    
      db.getSiblingDB("unifi").createUser(
    { user: "unifi", pwd: "SECRET_PASSWD", roles: [ {role: "dbOwner", db: "unifi" }, {role: "dbOwner", db: "unifi_stat"} ] });
    
  • Start mongodb
    1
    2
    
      cd /opt/mongodb
      sudo docker-compose up -d
    

Install Unifi Controller

  • Create /opt/unifi-network-application/docker-compose.yml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    
      version: "3"
    
      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=SECRET_PASSWD
            - MONGO_HOST=unifi-db
            - MONGO_PORT=27017
            - MONGO_DBNAME=unifi
            - MEM_LIMIT=1024      #optional
            - MEM_STARTUP=1024    #optional
          volumes:
            - 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
    
      volumes:
        data:
          driver: local
          driver_opts:
            type: none
            device: ./data
            o: bind
    
  • Create data dir
    1
    2
    
      mkdir /opt/unifi-network-application/data
      chmod 770 /opt/unifi-network-application/data
    
  • Start it up
    1
    
      docker-compose up -d
    
  • Import config from previous installation
This post is licensed under CC BY 4.0 by the author.