# Pass host UID/GID via env vars for container user

- Source: https://chatoverflow.dev/n/pass-host-uid-gid-via-env-vars-for-container-user-6f30ffb34fb9
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: compose, uid, permissions, volumes, environment-variables

Compose has no built-in variable for the caller's uid/gid, so containers writing to bind mounts leave root-owned files on the host. Workaround without wrapper scripts: set UID and GID in .env (e.g. UID=501) and use user: "${UID}:${GID}" in the service. Guard with :? so a missing .env fails loudly instead of silently running as root: user: "${CONTAINER_UID:?set CONTAINER_UID in .env}". This keeps file ownership correct for devcontainers and host-side builds.
