Can we pass PUID/PGID to the HA Docker container so I can edit files with vscode as normal user?

Here my Docker compose for HA.

    homeassistant:
        image: "ghcr.io/home-assistant/home-assistant:stable"
        hostname: homeassistant
        container_name: homeassistant
        network_mode: host
        restart: unless-stopped
        privileged: true
        volumes:
            - /data/docker/homeassistant:/config
            - /etc/localtime:/etc/localtime:ro
            - /run/dbus:/run/dbus:ro
        depends_on:
            - zwave
            - mosquitto

Everything works as expected. But I can’t open /data/docker/homeassistant in vscode and edit files cause everything in /data/docker/homeassistant is root:root.

The quick/easy fix seems to be to set the PUID/PGID environment variables to 1000 which is my primary user.

But I’m not sure if that will break things?

As a possible alternative, you could change the permissions of the files, either by making them writable for everyone, or by adding yourself to group “root” and make the files group-writable (a bit more safe).

Setting PUID/PGID could also work, but is more likely to break things.

Indeed, and specially: When you restart the container, most files will be reset to root:root, leaving you with a weird mix. Best to just leave it. I’ve tried.

This is the best option. I personally don’t edit files directly, but have an rsync script, so I don’t have exact knowledge of the VSCode app (add-on).

I created user and group in Linux 1002

services:
  homeassistant:
  user: 1002:1002

What is the basis of your reply? AFAIK, PUIDs and GUIDs aren’t globally unique in Linux (generally speaking, with the exception of e.g. root).

not sure why but HA docker container didnt respect puid/pgid or pid/gid. it did recognize and utilize “user”. the user will be unknown to docker container but services will run as user.

I have not checked puid/guid in past 1 to 2 yrs so maybe this has changed. I am running recent HA version so I have confirmed “user” is functioning and may resolve your file permission issue.

EDIT
and yes, if i remember setting PUID/PGID or variants did break things or maybe it just had no effect. tested long ago and did not document problems

I was able to solve this using setfacls on my Docker host to add my regular user. It works great.

I was wrong. HA is doing something that overwrites the ACLs. Doh.

Which is why I said:

Unless you run container with user: xxxx:xxxx defined