Update Home Assitant Docker container from Home Assistant

I have Home Assistant running in Docker container. Is it ever possible to execute a command from Home Assistant that recreates the container with the latest image pulled?

Or is it as stupid as sitting on the branch you are sawing?

Today I go to Portainer Web-UI (running on same host in another container) and click Recreate (pull latest image) on the Home Assistant container. Would be nice to have this in the Home Assitant interface…

Please advice me!

Some pointers, the way I do it with shell_commands
ha-host.lan is the host inside which HA runs as a container.

fetch_ha_image:  >
  ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no [email protected] 'nohup sudo /usr/bin/docker pull homeassistant/raspberrypi4-homeassistant:stable > /dev/null 2>&1 &'
rebuild_ha: >
  ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no [email protected] 'nohup sh -c "sudo docker-compose -f /opt/docker_files/homeassistant/docker-compose.yml build --pull && sudo docker-compose -f /opt/docker_files/homeassistant/docker-compose.yml up -d" > /dev/null 2>&1 &'

With a sudoers of

user ALL= NOPASSWD: /usr/bin/docker
user ALL= NOPASSWD: /usr/bin/docker-compose
2 Likes

I do understand the concept for doing it. Need to understand in detail how to adopt it in my setup. I use docker-compose to run all docker services on the machine, but I guess I’ll try to do a restart of only the Home Assistant container here, instead of interrupting all services.
Thanks for the ideas!

That’s what my code is doing :wink:

How would you handle breaking change?

Not sure what you mean.

I have a test instance where I have a first look, I read the release notes, I do daily backups, but besides that, you cannot actually be sure it won’t break before upgrading.

I think this answers the question

But, I do have all my docker containers configured in one single docker-compose file. So when I do docker-compose up or down, all services are affected.
Do I have to split it up?

I would issue the updates manually, but without having to ssh or go to another ui. So no auto-upgrades.

If by “all”, you mean “all”, then yeah, definitely.
A single docker-compose describes the necessary containers for a “project”, so to speak.

Now, you might have, eg, MQTT or MySQL in addition to HA. But if you just do a “up -d” after downloading the new image, it should only restart HA, iirc.

Yes, I do have Mosquitto, Influx, Grafana… and some other services in the same compose-file. Maybe I should split them up according to dependencies instead. :slight_smile: