devcontainers / devcontainers/spec
Create variables for remoteUser and host user's UID and GID
- Dominant language
- No language data
- Stars
- 5.7k
- Forks
- 496
- PR merge metrics
- No merged PRs in 30d
Description
Background:
I am trying to install homebrew in my devcontainer's image for use by the non-root `remoteUser`, since the system package manager will be unusable. However, this won't work reliably:
```dockerfile
ARG USERNAME=dev
RUN useradd -ms $(which bash) ${USERNAME}
ARG HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew
COPY \
--from=docker.io/homebrew/brew:latest \
--chown=${USERNAME} \
${HOMEBREW_PREFIX} ${HOMEBREW_PREFIX}
```
The problem is the [automatic UID update](https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_specifying-a-user-for-vs-code) (ie. the `updateRemoteUserUID` option). The update just modifies the UID:GID in the `/etc/passwd` file without actually changing ownership of anything, so the updated user no longer has access to `HOMEBREW_PREFIX` which is still owned by the pre-update UID:GID. So you can't use `brew` if the update executes. You could add ARGs for the host UID and GID (ie. what the update will change you to), but I'd prefer not to hardcode it in my dockerfile.
It would be better if we could add [pre-defined variables](https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson) for the host UID and GID which we could then add as build args via the `build.args` field. Making the `remoteUser` available as a pre-defined variable would also be helpful to avoid having to hardcode it in both `devcontainer.json` and the dockerfile.
Contributor guide
Assessment
This issue has not been assessed yet.