Move from Raspberry Pi to Docker: config-folder?

Hi,

I have read this discussion and I do have a follow-up question. What path do I have to copy the config-folder to? Only the config-folder or other folders as well?

I am not sure, what folder is acutally used by Docker.

  • my compose.yaml for HomeAssistant is in this directory: /home/uadmin/Docker/HomeAssistant/
  • The actual data seems to be in this folder: /var/lib/docker/volumes/homeassistant_HomeAssistent_config/_data

My compose.yaml:

# version: as of 23.12.2022: https://docs.docker.com/compose/compose-file/
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - HomeAssistent_config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
#    privileged: true
    networks:
      macvlan30:
        ipv4_address: 192.168.30.20
#    ports:
      # Portal Access
#      - "8123:8123"
#    privileged: true

volumes:
  HomeAssistent_config:
    driver: local


# Network specifications
networks:
  macvlan30:
    external: true

Is this the folder, which I have to backup, if I don’t want to loose my container data?

root@ubuntu:/var/lib/docker/volumes# ls -la
total 108
drwx-----x 19 root root   4096 Dec 29 14:17 .
drwx--x--- 13 root root   4096 Dec 29 14:17 ..
drwx-----x  3 root root   4096 Dec 16 23:52 2eb36a3d36cc7cd56a5446f6a9a6250ada701e36c9f97b87d0abef7fe9f9b7e5
drwx-----x  3 root root   4096 Dec 23 16:25 368e86bfb2209e3c04a3bf1137dd98b6c06293e652cff2ef9670c840d3a705be
drwx-----x  3 root root   4096 Dec 20 21:55 3741223ee20d251ae9ab7a5c5f6150e29b6aa357f639f35fea074f14bb47f458
drwx-----x  3 root root   4096 Dec 23 10:31 4254b425a70d7ca5078ba04c2053e216dd96005e63f08f4981779c4f2b0f6b4f
drwx-----x  3 root root   4096 Dec 23 10:31 42794cef720cb008bdd2160ed32e871fb611b408e333865b2474fc0f2d6bf79f
drwx-----x  3 root root   4096 Dec 23 16:25 6077a2c92d3523875277fb45e42e3de85d2d7ada3db82dc1cfa0ff57ff498b74
drwx-----x  3 root root   4096 Dec 19 09:33 83899e56583413127aa0c0fb5257e6ef60318bffe9bcdab1295b764a579c04c7
drwx-----x  3 root root   4096 Dec 17 00:18 93d882dafa796c86457d1c7e731bc5dbf4f25ad11c95d3312e13844cac02f6f6
drwx-----x  3 root root   4096 Dec 20 21:20 ab3b720182ace4ff17a00015611a95b67cfad71a6769e4822734f46f411ed03d
drwx-----x  3 root root   4096 Dec 17 00:59 b0c1b5efa8c0f48c7226b88dca4793d0cf6951245750f3e9ad872d4da2dc8220
drwx-----x  3 root root   4096 Dec 17 00:45 b5b9e4de8211ce02f1acb4a966b28675af1a9c4be03813d14d866b191a1256af
brw-------  1 root root 253, 0 Dec 29 14:17 backingFsBlockDev
drwx-----x  3 root root   4096 Dec 19 10:00 bf5adf2f0890b46dffe8b84c89ae5a5686ca24134a310ba8df8fffbec0cd609b
drwx-----x  3 root root   4096 Dec 16 23:52 c7212bc446b7d467d04bcc836e824b69c10733ce451c669badfdec94cf419e05
drwx-----x  3 root root   4096 Dec 16 23:50 graylog_es_data
drwx-----x  3 root root   4096 Dec 16 23:50 graylog_graylog_journal
drwx-----x  3 root root   4096 Dec 16 23:50 graylog_mongo_data
drwx-----x  3 root root   4096 Dec 24 00:35 homeassistant_HomeAssistent_config
-rw-------  1 root root  65536 Dec 29 14:17 metadata.db

Could I choose another folder to persist the HomeAssistant-data? Does it make sense to do so?

I would take a look at this topic, someone else recently moved from an RPI to docker install and questions and details are over here

Yes and I would recommend another folder, and the install documentation recommends you persist in a folder on the host you define as well (see here - Linux - Home Assistant)

This article explains the different ways volumes work in docker - Docker Volumes – Host vs. Anonymous vs. Named Volumes

It looks like you are using a named volume for Home Assistant in docker. I don’t like using that since, as you’ve seen, the data is buried in the var/lib/docker folder and not easily accessible.

Instead, I would map the config volume directly to a folder on your host. Assuming the host is some version of linux, you can go to your user directory and just create a folder called “homeassistant”.

For example, if your user name on linux is “schneich”, you can just create a folder at /home/schneich/homeassistant. In that folder, copy the entire config directory out of Home Assistant from the old machine/instance over to the new machine/OS. This could be done by either extracting the .tar file of the home assistant backup in your new directory, or manually copying everything over. Make sure you use “sudo” when copying any files as some have root permission, and won’t copy without sudo.

You really can put those config files anywhere on the machine you want in any folder you want, and the key is that they are easily accessible on the host. You’ll want them accessible in case you need to edit your config.yaml, or you need to do a backup. The key is to map that folder to your homeassistant container under your volume flag.

So in the below compose, if your put the config files on the host in /home/schneich/homeassistant, the homeassistant container would access that volume and “map” the data to container, and persist that config data there in between container restarts/updates.

# version: as of 23.12.2022: https://docs.docker.com/compose/compose-file/
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/schneich/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
#    privileged: true
    networks:
      macvlan30:
        ipv4_address: 192.168.30.20
#    ports:
      # Portal Access
#      - "8123:8123"
#    privileged: true


# Network specifications
networks:
  macvlan30:
    external: true

Also, any reason you want to use a macvlan over host networking? The install documentation I linked above recommends using host networking for most normal install situations, although some have used a macvlan but only in specific use cases.

Hi @mwav3,

thank you for all your references and inputs.

volumes
I tried to map the folder /home/uadmin/Docker/HomeAssistant/config, but it did not work as I tried it with relative paths… There are 3 other containers, where I had the same issue. I am not sure, but I thought docker compose gave me some errors with absolute paths, but I will try again.

networks
Short answer: yes, I want to use a macvlan. (Well, I tried with ipvlan, but that did not work out as I wanted to.)
Long answer: I have one Ubuntu server, hosting my docker environment, within which I plan to run several containers. As my home network is separated in different vlans, I want to put some of the containers into vlan30, others in vlan70. (Here are all the details, if you are interested in: How to set host and containes in same vlan - General Discussions - Docker Community Forums - any input in that issue is welcome…)

I have two more questions:
ports
As I use a macvlan: do I need to configure the ports within the compose.yaml? (Or are all ports open to that container?)

privileged
What does the “privileged: true” mean? As far as I can see, HomeAssistant is running, even though I did not grant those privileges.

many thanks four your valuable feedback,
Chris

Sounds like a permissions issue. What is the host os? Try following these docker post install steps to give the docker user proper permissions.

https://docs.docker.com.xy2401.com/install/linux/linux-postinstall/

I have not used a macvlan myself, but this sounds like a good use case for it. You may however have issues with Home assistant discovery finding devices running in different networks.

If using host networking or a macvlan there is no need to also specify ports, as they are all open to the container.

Priviledged gives the container full access to all the resources on the host machine. If you are using zha and need to map a zigbee stick, it would do that for you, but a better way is to use the device flag

I didn’t like when they changed this, and posted reasons Here.

Priviledged mode is not a good idea and should be avoided whenever possible . If you don’t need to map a zigbee stick to zha, there is absolutely no reason for home assistant to run in priviledged mode.

Hi @mwav3,

I changed my docker compose.yaml to this:

# version: as of 23.12.2022: https://docs.docker.com/compose/compose-file/
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - home/uadmin/Docker/HomeAssistant/HomeAssistent_config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
#    privileged: true
    networks:
      macvlan30:
        ipv4_address: 192.168.30.20
#    ports:
      # Portal Access
#      - "8123:8123"

volumes:
  HomeAssistent_config:
    driver: local


# Network specifications
networks:
  macvlan30:
    external: true

and this is the error:

uadmin@ubuntu:~/Docker/HomeAssistant$ docker compose up -d
service "homeassistant" refers to undefined volume home/uadmin/Docker/HomeAssistant/HomeAssistent_config: invalid compose project

ok, error in the path. it has to start with “/”…

# version: as of 23.12.2022: https://docs.docker.com/compose/compose-file/
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/uadmin/Docker/HomeAssistant/HomeAssistent_config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
#    privileged: true
    networks:
      macvlan30:
        ipv4_address: 192.168.30.20
#    ports:
      # Portal Access
#      - "8123:8123"

volumes:
  HomeAssistent_config:
    driver: local


# Network specifications
networks:
  macvlan30:
    external: true