UniFi Network Server with Docker
LinuxServer.io makes some great Docker images. I’ve been using their UniFi Controller image for a very long time. Sadly it is being deprecated in January 2024. Fortunately, they have a new replacement image named UniFi Network Application. There’s a bit more to the setup as the database portion has been decoupled from the image.
In this post, I’ll show you step-by-step how to set up the UniFi Network Application with Docker.
The UniFi Network Application uses MongoDB for its database we will need to set that up. MongoDB is composed of two elements, the main database and a stats database.
When you first make a MongoDB container it needs to be initialized there are a few methods to do this. I’ll be using the shell script method as I was able to make that word with all the environment variables I wanted to use.
- Make a folder to store everything in. I’ll call mine unifi-net-app.
- Download the
init-mongo.sh, and the
sample.envfiles from my GitHub https://github.com/thedxt/UniFi-Docker and place them in the folder.
sample.envfile shows you the variables you will need to define.
- The variables are:
CONTAINER_NAMEis the name of your UniFi stack. There will be two containers spawned.
- The one with
_COREappended to it is the LinuxServer.io UniFi Network Application image.
- The one with
_DBappended to it is the official MongoDB image. It is currently pinned to version 4.4 as that’s the highest version UniFi supports.
- The one with
MONGO_DBNAMEis the name of the MongoDB database that stores all the data. The second database for stats will have
_statappended to it.
MONGO_USERis the database user for the UniFi database and the stats database.
MONGO_PASSis the password for the database user for the UniFi database and the stats database.
TIME_ZONEthis sets the time zone for the UniFi Network Application. Here’s a list of the valid TZ identifier entries.
- Make a new file named
.envwith all the variables above defined.
Below is an example of what the
.env file could look like.
TIME_ZONE=America/EdmontonCode language: plaintext (plaintext)
- Now you can start your Docker container and you will have a working UniFi Network Server Application.
How It Works
.env file contains the variables that are used by the
docker-compose.yml file and the
init-mongo.sh file making it so you only have to define everything in one place which lowers the chance of typos and makes everything work easily.
There are two folders created, one of them is named
core-data which is the config directory for the LinuxServer.io UniFi Network Application image. The other folder is named
db-data this is where MongoDB stores the database files.
My docker compose file changes nothing with how the LinuxServer.io UniFi Network Application image works or how the MongoDB images works, I just added variables that work with the
.env file. This means if you want to add other items that either image supports you can just add them to the docker compose file.
Extra UniFi Ports
In the docker compose file I only defined the minimum required ports that I needed. You can add more ports if you need them.
The ports I defined are
- UDP 3478 for STUN. UniFi does not work without it.
- UDP 10001 for local UniFi device discovery.
- TCP 8080 for UniFi devices to communicate with the UniFi controller.
- TCP 8443 for the Web UI of the UniFi controller.
- TCP 8843 for HTTPS redirection for guest hotspots.
- TCP 8880 for HTTP redirection for guest hotspots.
Here’s a list of all the ports that UniFi could use.