agent-infra / agent-infra/sandbox

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

Open
#102 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
5.9k
Forks
529
Avg merge
4h 8m
Merged PRs (30d)
4

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.