agent-infra / agent-infra/sandbox

Permission errors when mounting host directories into Docker container (Possible solution)

Offen
#102 3 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
5.9k
Forks
529
Ø Merge
4 Std. 8 Min.
Gemergte PRs (30 T.)
4

Beschreibung

When mounting a host directory into the Docker container, permission errors may occur, making it impossible to write to or modify files inside the mounted directory. This happens because the default `gem` user created inside the container has a UID/GID that does not match the UID/GID of the host user.

### Root cause

The container creates the `gem` user at startup with a default UID/GID, which may differ from the host user’s UID/GID. As a result, file operations on bind-mounted directories fail due to permission mismatches.

### Possible solution

A simple workaround is to explicitly set the following environment variables in `docker-compose.yml`:

* `USER_UID: ${UID}`
* `USER_GID: ${GID}`

Here, `${UID}` and `${GID}` refer to the host user’s UID and GID, which can be obtained via `id -u` and `id -g`.

With these variables set, the `gem` user created at container startup will have matching UID/GID values, resolving the permission issues on the mounted directory.

### Implementation detail

The container’s entrypoint script creates the user based on the `USER_UID` and `USER_GID` environment variables.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.