Upgrading HomeAssistant in Docker

Hi All

Total Noob here so please bear with me.

I have read countless posts but feel completely out of my depth

I have a tiny think PC running Ubuntu, and installed HomeAssistant in docker many months ago. I havent ever tried updating it as i didnt know what i was doing

Now looking into it and im struggling to work out how to proceed.

I installed it originally using:

sudo docker run -d 
  --name=homeassistant 
  --restart=always 
  --network=host 
  -v /etc/homeassistant:/config 
  homeassistant/home-assistant:stable

its been running fine for the last few months but i just want to know how to update it

I can see it all running fine when i SSH in and run this: docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be497a7c15ac homeassistant/home-assistant:stable “/init” 4 months ago Up 4 months homeassistant

i came across some posts suggesting to “rm” the container, repull it and then its good to go, but was worried about where i have the config saved, will that be ‘safe’ or is that inside the docker container?
(i have made a backup “core_2023_6_3.tar” and saved it to my PC in case…)

any advice (in baby steps) would be really appreciated!!

System Information:

Version core-2023.6.3
Installation Type Home Assistant Container
Development false
Supervisor false
Docker true
User root
Virtual Environment false
Python Version 3.11.4
Operating System Family Linux
Operating System Version 5.19.0-46-generic
CPU Architecture x86_64
Timezone Europe/London
Configuration Directory /config

Home Assistant Community Store

GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.33.0
Stage running
Available Repositories 1339
Downloaded Repositories 7

TIA
Kyle

Hi,

The answer you need is in the docs here:

so:

docker pull ghcr.io/home-assistant/home-assistant:stable

then:

docker stop homeassistant

then:

docker rm homeassistant

then your original command above:

sudo docker run -d 
  --name=homeassistant 
  --restart=always 
  --network=host 
  -v /etc/homeassistant:/config 
  homeassistant/home-assistant:stable

However, this could be a little easier using a compose.yaml file (which holds all the details of the last command) and would look like:

services:
  homeassistant:
    container_name: homeassistant
    image: ghcr.io/home-assistant/home-assistant:stable
    volumes:
      - etc/homeassistant:/config
    network_mode: host
    privileged: true
    restart: always

then, your commands would be reduced to:

docker compose pull

and

docker compose up -d

[edit: typos and clarity]

4 Likes

indeed thats what i started doing but then got scared that my config was saved inside the container - is that even possible?

so with what you suggest there, the config is saved elsewhere and when i remove the container, then readd it with the original commands i did then it puts it back into the same place, and it re-uses the config file that was contained (safely) elsewhere and i should be up and running again?

if that works ill look int the compose suggestion (i have scrypted running on another docker container - would that be affected by this method?)

is there any way of checking that the config directory really is in the etc/homeassistant folder? when i look at the “System Information” it just says /config… just want to be sure i dont mess that up and lose the config

thank you!!

Yes, possible, but the following line of your docker up command maps HA’s config to:

/etc/homeassistant

Go to that directory and you should be able to see your config there (note: some data is in an invisible folder called .storage. You can place it anywhere you like:

Your HA-generated backups should be in a directory called /backups within etc/homeassistant.

-v <path-to-data>:/config 

I’m not sure if \etc is a good place to have it or not.

1 Like

Sort of. The config directory doesn’t go anywhere - it’s always at /etc/homeassistant *unless you mobile it yourself). Both the new and old HA containers are mapped to it (HA know’s to use it the data there.

SSH to that directory and take a look. you should see something like the following:
Screenshot 2023-11-23 at 14.35.00

Your’s will look a little different (you won’t have ‘JCHH’ directory and you will have a few other files) and don’t forget some of the files and directories are hidden.

yes i see something pretty similar… that gives me the confidence to go ahead with the lines of code above! thank you

Backup first!!!

1 Like

yes i have a backup indeed

i just tried all those steps but its still showing as
Home Assistant 2023.6.3
Frontend 20230608.0 - latest

when i run docker ps i get this, so pretty sure that it creatred an fresh container…
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
467d995b4bac homeassistant/home-assistant:stable “/init” 56 seconds ago Up 55 seconds

is it because of the lower line?

or do i need this instead?

I never use “stable”. I always use “latest” instead.

also I really recommend looking into and installing Portainer. It is installed in a docker container as well and simplifies a lot of things you normally do with docker.

For example, to update home assistant all I do is open the container in Portainer and click on ‘recreate’. there is a check box there asking if you want to pull the latest image. then click recreate.

it will download the latest image, stop the container and restart the container using that image.

literally, 5 clicks.

1 Like

Is it possible you have 2 instances of HA running (it is possible)?
Type the following and post back

docker container -ls

@jchh thanks for responding, as above here is the full printout of “docker container ls”, its the same as i posted for “docker ps”

XXX@YYY:~$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
467d995b4bac homeassistant/home-assistant:stable “/init” 20 hours ago Up 19 hours homeassistant
23b2cd35435a koush/scrypted:latest “/init /bin/sh -c 'n…” 37 hours ago Up 19 hours scrypted
17c5713c4110 f847e1adb570 “/watchtower --inter…” 6 months ago Up 19 hours 0.0.0.0:10444->8080/tcp, :::10444->8080/tcp AonzPHmmRQVTjkhtlqOuoyEmoiyRJhal

brilliant, i installed Portainer following these instructions:

logged into the web interface and followed your instructions:

then re-create with latest image
image

thank you both for your help, im now on the latest build

1 Like

@finity

i see there is an old Image in Portainer
can i just delete the old one that is flagged as “Unused”? to save the 2GB?

Which is terrible advice.

latest is just the most recent build, which may not be stable (could be beta, could even be dev).

I’ve been using HA since .35 and Docker install for over 5 years and I’ve literally never had any issues using ‘latest’. The ‘latest’ tag has always been the most recent point version of the monthly release.

While that may be true for other projects I’m pretty sure the beta/dev versions of HA never get a ‘latest’ tag. At least I’ve never seen it in my experience.

and I think by definition when it comes to HA there is never a truly ‘stable’ build.

“terrible” is certainly in the eye of the beholder.

yes, you can delete any images that are tagged unused.

1 Like

Which folder should the compose.yaml file saved to? config folder?