Unifi Network Application in Docker

Table of Contents:

Intro

Unifi is changing a little bit, again. I’m running the Unifi Controller in Docker for years now, due to a network upgrade I had to move mine to a new Docker host. So far, nothing special. But.

I’m a big fan of the LinuxServer.io stack and so, my Unifi Controller is also the one from them. While migrating all other containers, I saw in the logs that their Controller container will be deprecated soon (full info here). Time to switch to the new Unifi Network Application. Let’s setup a completely new instance of that step by step in the following writing.

Requirements

  • Internet access
  • A Docker host which will run the following containers:
    • the Unifi Network Application
    • as well as it’s MongoDB database
  • A folder on the Docker host where we put all data of the containers (so-called volume mounts) to make everything persistent. My base directory will be /docker.

Install and configure the MongoDB database

First of all, we’ll setup the database container based on MongoDB. Beware that I’m using version 4.4 (which is not the latest one), according to the documentation it should also work with newer versions.

Let’s prepare the database, it’s user and password to be used by the Unifi Network Application container later on. All we need to do is to pass some script at the initial start of the container. Create a file inside /docker/unifi-mongodb/ with the name init-mongo.js and the content:

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

This line means:

  • Main database name is unifi
  • User is unifi
  • Password is ThisIsMySuperSecurePassword!
  • Roles (permissions) are set for the database name unifi –> beware of the second _stat database which starts with firsts database name

This file will create the database, it’s user and permissions and must be part of the initial container start.

After that, the container can be spawn up:

docker run -d \
  --name=unifi-mongodb \
  -p 192.168.199.50:27017:27017 \
  -v /docker/unifi-mongodb/data:/data/db \
  -v /docker/unifi-mongodb/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro \
  --restart unless-stopped \
  mongo:4.4

Make sure to change the Docker host IP (or virtual IP) as well as the directory according to your needs. If you need to change anything or made a mistake, delete the content of the /docker/unifi-mongodb/data/ directory and start from scratch - this is necessary because the script is a init-script and will only be run once at container start.

Install and configure the Unifi Network Application

After the MongoDB container runs without errors, we can spawn up the Network Application container using this command:

docker run -d \
  --name=unifi-network-application \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Europe/Stockholm \
  -e MONGO_USER=unifi \
  -e MONGO_PASS='ThisIsMySuperSecurePassword!' \
  -e MONGO_HOST=192.168.199.50 \
  -e MONGO_PORT=27017 \
  -e MONGO_DBNAME=unifi \
  -e MEM_LIMIT=1024 \
  -e MEM_STARTUP=1024 \
  -p 192.168.199.50:8443:8443 \
  -p 192.168.199.50:3478:3478/udp \
  -p 192.168.199.50:10001:10001/udp \
  -p 192.168.199.50:8080:8080 \
  -p 192.168.199.50:1900:1900/udp \
  -p 192.168.199.50:8843:8843 \
  -p 192.168.199.50:8880:8880 \
  -p 192.168.199.50:6789:6789 \
  -p 192.168.199.50:5514:5514/udp \
  -v /docker/unifi-network-application:/config \
  --restart unless-stopped \
  lscr.io/linuxserver/unifi-network-application:latest

Again, make sure to change / adapt:

  • your time zone
  • the Docker host IP (or virtual IP)
  • the directory according to your needs
  • container memory limits (optional)

Double-check if you copied the correct MONGO parameters from the container before.

That’s it! After some minutes, the “new” Unifi Network Application should be accessible via https://192.168.199.50:8443.

If you like posts like that and want to support me, some sats (see my about page) are highly appreciated 🧡