UniFi Network Server with Docker

UniFi Network Server with Docker
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.

Setup

  • Make a folder to store everything in. I’ll call mine unifi-net-app.
  • Download the docker-compose.yml, the init-mongo.sh, and the sample.env files from my GitHub https://github.com/thedxt/UniFi-Docker and place them in the folder.
  • The sample.env file shows you the variables you will need to define.
  • The variables are:
    • CONTAINER_NAME is the name of your UniFi stack. There will be two containers spawned.
      • The one with _CORE appended to it is the LinuxServer.io UniFi Network Application image.
      • The one with _DB appended to it is the official MongoDB image. It is currently pinned to version 4.4 as that’s the highest version UniFi supports.
    • MONGO_DBNAME is the name of the MongoDB database that stores all the data. The second database for stats will have _stat appended to it.
    • MONGO_USER is the database user for the UniFi database and the stats database.
    • MONGO_PASS is the password for the database user for the UniFi database and the stats database.
    • TIME_ZONE this sets the time zone for the UniFi Network Application. Here’s a list of the valid TZ identifier entries.
  • Make a new file named .env with all the variables above defined.

Below is an example of what the .env file could look like.

CONTAINER_NAME=unifi-net
MONGO_DBNAME=unifi-mongodb
MONGO_USER=unifi-user
MONGO_PASS=hkjfhshgjsdfhjf
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

The .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.

7 responses to “UniFi Network Server with Docker

Fabrizio Smilovich

I followed the instructions but controller won’t start when accessing https://localhost:8443

Daniel Keer

Do you have something else running on8443 on your host? When you start your container what do the logs say?

Florian

Thanks for your Work, it will work without any error!

Daniel Keer

I’m glad to hear that! Thank you!

Travis K

Thank you so much! Linuxserver.io makes this more complicated than it needs to be. Your docker-compose worked great!

Btw, Unifi 8.1 now supports MongoDB 7.0. I changed my docker-compose MongoDB version to 7.0, and I needed to change the init-mongo.sh script to use the binary “mongosh” instead of “mongo”, which is new in mongo 7.0 and it works great!

Daniel Keer

No problem! Glad it all worked.

Thanks for the heads up about Unifi 8.1 now supporting MongoDB 7.0.

Leave a comment

Your email address will not be published. Required fields are marked *