Docker image for the Unifi Network Controller software
- Ubuntu
22.04 LTS
- Unifi Network Controller
v7.4.162
- MongoDB
v3.6.23
- openjdk
v11.0.20
Building the docker image:
sudo docker build --tag unifi:latest .
Create a /etc/systemd/system/unifi.service
file with the following content:
- NOTE: replace
<path to your docker-compose.yml>
below with your system's path
[Unit]
Description=Unifi Docker Compose App Service
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/docker-compose -f <path to your docker-compose.yml> up -d
ExecStop=/usr/local/bin/docker-compose -f <path to your docker-compose.yml> down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
Install the service:
sudo systemctl enable unifi
In docker-compose.yml
you can customize the following environmental variables:
JAVA_OPTS
: Extra command line flags to pass to the Java runtime when the Unifi application is started. For example,"JAVA_OPTS=-Xmx1024M"
would set the runtime Java heap limit to 1024MB.
In docker-compose.yml
there are 3 volumes you can map out of the container to your docker host since the Unifi application is not running as root
:
- By default, the user ID and group ID of the image user is
6969
. You can change this in theDockerfile
before building the image to suit your needs.
Container Directory | Default Docker Volume in docker-compose.yml |
---|---|
/usr/lib/unifi/data |
unifi_data |
/usr/lib/unifi/logs |
unifi_logs |
/usr/lib/unifi/run |
unifi_run |
Start the service and browse to https://<host-ip>:8443
:
sudo systemctl start unifi
Your container data host location can be found by running the following docker commands:
sudo docker volume ls
sudo docker volume inspect <volume_name>
NOTE: If you are having trouble getting devices to be adopted by the unifi controller, you may need to set the controller hostname/IP manually under controller settings and check the box to override the controller hostname/IP. The controller hostname can be the FQDN for your controller on your network or the IP you statically assign the controller from your DNS server:
see this Unifi forum discussion post for more info
Unifi Network Controller installation steps taken from these sources:
- https://stoffelconsulting.com/install-unifi-5-8-x-on-ubuntu-18-04-lts/
- https://help.ubnt.com/hc/en-us/articles/220066768-UniFi-How-to-Install-and-Update-via-APT-on-Debian-or-Ubuntu
Helpful Docker debugging commands:
# stop all running containers
sudo docker stop $(sudo docker ps -aq)
# delete all containers
sudo docker rm $(sudo docker ps -a -q)
# delete all docker images
sudo docker image prune -a -f
# delete all unmapped docker volumes
sudo docker volume rm $(sudo docker volume ls -q)
# clear docker build cache
sudo docker buildx prune -f
# start a bash shell in the unifi image
sudo docker run -it --entrypoint /bin/bash unifi:latest -s
# view logs from unifi-controller container
sudo docker logs unifi-controller
# reload changes to /etc/systemd/system/unifi.service
sudo systemctl daemon-reload
# start a bash shell in a running container
sudo docker exec -it "id of running container" bash
For image development & updating, the following script is helpful:
#!/bin/bash
set -e
echo '[!!!] stopping unifi service ...'
sudo systemctl stop unifi
echo '[!!!] stopping unifi containers ...'
sudo docker stop $(sudo docker ps -aq)
echo '[!!!] removing unifi containers ...'
sudo docker rm $(sudo docker ps -aq)
# NOTE: this will delete any backups!
#echo '[!!!] deleting unifi volumes ...'
#sudo docker volume rm $(sudo docker volume ls -q)
echo '[!!!] deleting images ...'
sudo docker image prune -a -f
sudo docker buildx prune -f
# goto location of repo with Dockerfile and rebuild image
# NOTE: assumes git repo in home directory of current user
echo '[!!!] re-building unifi image ...'
cd ~/docker_unifi/
sudo docker build --tag unifi:latest .
echo '[!!!] starting unifi service ...'
sudo systemctl start unifi &
watch -n 0.5 sudo docker logs unifi-controller