Moving HomeAssistant config from docker

Let me start with a confession. Many months ago I was too impatient to start with HA and I have been lacking my security responsibilities since. Time for change and since I couldn’t find a comprehensive guide, let me write another incomprehensive guide. But hopefully it will be the piece of the puzzle you’re missing.

So what went wrong? I installed HA docker image without a separate location for the config and couldn’t update the image because of it. Last week I took the plunge and went to fix this issue. What had to happen?

  • Creating a backup for my current docker image / HA instance
  • Creating a new HA instance with the config file on a location outside of the docker image
  • Moving the current configuration to the new docker image

Prerequesites

If, like me, this action also includes an upgrade, check the release notes for breaking changes and please update and/or upgrade your system before moving the configuration. In my case, my z-wave integration broke for example and HA couldn’t run because of an outdated libseccomp2.

Creating a backup for my current HA instance

To be able to use the ‘normal’ docker commands provided by HA, I wanted to rename the current docker installation so it wouldn’t get overwritten and still be able to function while configuring the rest. I did this with the command docker rename homeassistant oldhomeassistant after first running docker stop homeassistant. This renames the homeassistant docker container to ‘oldhomeassistant’, which is helpfull because you can now install a new container while still running the old one. Be aware that you can only access one at a time, so you’d have to stop the old one to test the new one. docker start oldhomeassistant to be sure the container ‘oldhomeassistant’ still works as expected before you install the new container.

Create new HA container with persistent config file

This part you mostly know from https://www.home-assistant.io/installation/raspberrypi. I created a folder for persistent storage of the configuration files under the /etc dir with sudo mkdir /etc/homeassistant/config/ and pointed the docker run command to it.

docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=Europe/Amsterdam \
  -v /etc/homeassistant/config:/config \
  --network=host \
  --device=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0:/dev/rflink \
  ghcr.io/home-assistant/home-assistant:stable

Check if the configuration.yaml and other files appeared under /etc/homeassistant/config. If true then docker stop homeassistant

Copying config from docker to pi

This is the important part. Make sure all containers are stopped with docker ps -a | grep homeassistant which should return two ‘exited’ containers.
Then run sudo docker cp homeassistantold:/config /etc/homeassistant/ to copy all files from the old docker container to the location from which the new docker container gets its configuration files. If this is done you should be able to docker start homeassistant and opening your homeassistant in the browser you should see some familiar information.


by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *