Recently I reinstalled my Raspberry Pi where I was running Home Assistant, Pi hole and Unifi controller within Docker. This
was working fine for a while, until my SD card was corrupt.
Docker was running rootless, and apparently the problem with that is that Docker was only running when there is a user
session.

Steps to reproduce problem:

  1. SSH to Raspberry pi
  2. Docker seems to start all containers.
  3. Close SSH connection
  4. Docker stops all containers

Solution:

You need to enable lingering:

sudo loginctl enable-linger $(whoami)