Skip to content
Ryan Schlesinger edited this page Apr 6, 2024 · 20 revisions

Welcome to the docker-unifi-rpi wiki!

Find yourself a computer! It can be a raspberry pi, a server, etc.

If you're running on a raspberry pi, I personally prefer ubuntu server: https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview

Now let's install docker.

System Setup

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Container Setup

sudo mkdir /opt/unifi

There are 3 different ways to set up unifi with this image.

Local Network

Create the following file in /opt/unifi.

  • compose.yml:
services:
  unifi:
    image: ryansch/unifi-rpi:latest
    container_name: unifi
    restart: unless-stopped
    environment:
      JAVA_OPTS: -Xmx1024M
    network_mode: host
    volumes:
      # Unifi v5.0.7 creates all of these directories (some remain empty)
      - config:/var/lib/unifi
      - log:/usr/lib/unifi/logs
      - log2:/var/log/unifi
      - run:/usr/lib/unifi/run
      - run2:/run/unifi
      - work:/usr/lib/unifi/work

volumes:
  config:
  log:
  log2:
  run:
  run2:
  work:

See: Common Setup

Container Networking

Create the following file in /opt/unifi.

  • compose.yml:
services:
  unifi:
    image: ryansch/unifi-rpi:latest
    container_name: unifi
    restart: unless-stopped
    environment:
      JAVA_OPTS: -Xmx1024M
    ports:
      - "3478:3478/udp"
      - "8080:8080"
      - "8443:8443"
      - "8880:8880"
      - "8843"
      - "6789:6789"
    volumes:
      # Unifi v5.0.7 creates all of these directories (some remain empty)
      - config:/var/lib/unifi
      - log:/usr/lib/unifi/logs
      - log2:/var/log/unifi
      - run:/usr/lib/unifi/run
      - run2:/run/unifi
      - work:/usr/lib/unifi/work

volumes:
  config:
  log:
  log2:
  run:
  run2:
  work:

See: Common Setup

Container Networking w/ Caddy

Create the following files in /opt/unifi.

  • compose.yml:
services:
  unifi:
    image: ryansch/unifi-rpi:latest
    container_name: unifi
    restart: unless-stopped
    environment:
      JAVA_OPTS: -Xmx1024M
    ports:
      - "3478:3478/udp"
      - "8080:8080"
      - "8443"
      - "8880:8880"
      - "8843"
      - "6789:6789"
    volumes:
      # Unifi v5.0.7 creates all of these directories (some remain empty)
      - config:/var/lib/unifi
      - log:/usr/lib/unifi/logs
      - log2:/var/log/unifi
      - run:/usr/lib/unifi/run
      - run2:/run/unifi
      - work:/usr/lib/unifi/work

  caddy:
    image: caddy:2-alpine
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "8443:8443"
      - "4443:4443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

volumes:
  config:
  log:
  log2:
  run:
  run2:
  work:
  caddy_data:
  caddy_config:
  • Caddyfile:
{
	log default {
		output stdout
		format json
	}
}

CHANGEME_HOSTNAME:8443 {
	redir https://CHANGEME_HOSTNAME{uri} permanent
}

CHANGEME_HOSTNAME {
	reverse_proxy https://unifi:8443 {
		transport http {
			tls_insecure_skip_verify
		}
	}
}

Change CHANGEME_HOSTNAME to your public hostname.

Common Setup

Create:

  • unifi.service:
[Unit]
Description=Unifi Controller
After=docker.service
BindsTo=docker.service

[Service]
TimeoutStartSec=0
TimeoutStopSec=30
Restart=always
RestartSec=10

WorkingDirectory=/opt/unifi

ExecStartPre=-/usr/bin/docker compose kill
ExecStartPre=-/usr/bin/docker compose rm -f

ExecStart=/usr/bin/docker compose up --force-recreate

ExecStop=/usr/bin/docker compose stop

[Install]
WantedBy=multi-user.target

Run it!

cd /opt/unifi
sudo systemctl enable --now /opt/unifi/unifi.service
docker compose logs -f

Press ctrl+c to exit the logging output.