Container not started but UI still working?

Hello

I am running HA as a container under Ubuntu (configuration details below), with port 80 mapped to 8123 so I can use the UI without typing the port number in the URL.

System is set to start the HA container with a service using docker-compose (compose file below).

Everything seems to work fine but I am facing a weird situation I cannot explain: sometimes, the HA service fails to start, but the UI is still working (!).

  • when restarting the service (systemctl restart), the HA container fails to start because port 80 is in use (the container remains in Created state)
  • the process that owns the port is python3 -m homeassistant --config /config (apparently running on the host)
  • the parent process of the python3 process is s6-supervise home-assistant
  • a new python3 process appears each time I kill it
  • command docker ps -a is not showing any other container

I had a hard time installing HACS because the procedure I followed required unzipping the package from within the container (using docker exec), which therefore must be running. At one point I was able to start the container (not sure how, maybe when I tried without the port mapping), but I find that my setup is not very stable.

Can someone explain what is going on? Am I doing something wrong? I suspect this might have something to do with ‘snap’, but it’s just a wild guess.

Cheers,

JC

  • Minisforum N40 (Celeron N4020) + Sonoff Zigbee USB Dongle Plus ZBDongle-P (TI CC2652P)
  • Ubuntu server 22.04.3 LTS x86_64
  • Docker version 24.0.5, API version 1.41 (downgraded from 1.43)
  • Docker Compose 1.29.2-1
  • Ethernet cable to my router, fixed IP
  • Disabled built-in wifi and bluetooth
  • HA container image version 2023.10.5,
  • ZHA integration
  • HACS integration 1.33.0

Compose file

version: '3.7'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:2023.10"
    ports:
      - 80:8123
    volumes:
      - /home/home/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
    restart: unless-stopped
    privileged: true

Service file (/etc/systemd/system/homeassistant.service)

[Unit]
Description=HomeAssistant
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/home
ExecStart=/usr/bin/docker-compose -f /home/home/homeassistant.yaml up -d
ExecStop=/usr/bin/docker-compose -f /home/home/homeassistant.yaml down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

You should look at the log file.
The one name .log.1 should be the one from the previous run.

The HA log shows it’s starting and running successfully, which is the case.

Following more experiments, things are working as expected when I remove the port mapping (80:8123).

I really do not understand the system’s behavior when the port is mapped. Isn’t this the right way of doing this?

The port mapping should have no influence on HA.
Seen from HAs perspective it is just another connection on port 8123.
It might be an issue in your router then.

restart: unless-stopped

Keep in mind that this will restart the HA container together with the docker service after a reboot. It means "restart the container unless an explicit docker stop is done.

So your systemd unit will actually start a second instance of the container, and likely have conflict on port 80.

That is actually not related to a reboot.

It means that if the system is running and HA is crashing (or getting killed) then it will be restarted again.
Only if the service is stopped properly with a stop command will it staying stopped.

Indeed, but a side effect is that the container will be restarted after a reboot because it was not

So, if you also have a systemd unit starting the container on boot, there will be a race for the port 80, and probably a restart loop for one of the containers.

(My) bottom-line: Have systemd or docker handle the restarts, but not both. If you use systemd, set restart: no in docker-compose.

The restart parameter online affect a crash or kill after the service have been attempted started by the systems first.
If the systemd is succeeding then the restart parameter will not take effect.