Skip to content

Docker configuration files for a UniFi Network Controller container

License

Notifications You must be signed in to change notification settings

a-rey/docker_unifi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ubuntu Docker Unifi Network Controller

Docker image for the Unifi Network Controller software

Unifi Logo

Install:

Versions:

  • Ubuntu 22.04 LTS
  • Unifi Network Controller v7.4.162
  • MongoDB v3.6.23
  • openjdk v11.0.20

Build:

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

Settings:

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 the Dockerfile 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

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

Development Notes:

Unifi Network Controller installation steps taken from these sources:

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

About

Docker configuration files for a UniFi Network Controller container

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published