#11333: fix(docker): align host directory ownership with container user
docker
stale
Cluster:
Docker Configuration Improvements
## Summary
The Docker container runs as `node` (uid 1000, gid 1000), but `docker-setup.sh` creates the config and workspace directories on the host without adjusting ownership. When the host user is root (common on Linux servers), the mounted directories are owned by `root:root`, causing `EACCES` errors when the container tries to write config files, extensions, or workspace data.
## Root Cause
`docker-setup.sh` runs:
```bash
mkdir -p "$OPENCLAW_CONFIG_DIR"
mkdir -p "$OPENCLAW_WORKSPACE_DIR"
```
These directories inherit the host user's uid/gid (often root). The Dockerfile then runs:
```dockerfile
USER node # uid 1000, gid 1000
```
Result: the container cannot write to its own config/workspace mounts.
## Fix
Add `chown` after `mkdir` to align directory ownership with the container user:
- **Root host user**: `chown` is mandatory and will always succeed
- **Non-root host user**: `chown` is best-effort (may already match, or may lack permission — either way the script continues)
- **Custom setups** (rootless Podman, remapped uids): Override via `OPENCLAW_CONTAINER_UID` / `OPENCLAW_CONTAINER_GID` env vars
## Changes
- `docker-setup.sh`: 15 lines added after `mkdir` calls
## Testing
Verified the script passes `shellcheck` and `bash -n` syntax checks. The fix matches the workaround confirmed working by multiple users in the issue thread (`chown -R 1000:1000 "$HOME/.openclaw"`).
Closes #5434
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `docker-setup.sh` to `chown` the host config and workspace directories to match the container’s `node` user (uid/gid 1000 by default, overridable via env vars), preventing `EACCES` when those host paths are bind-mounted into the container.
One issue to address before merge: the ownership adjustment is not recursive, so pre-existing root-owned contents under these directories can still cause `EACCES` even though the top-level directories are fixed.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but may not fully fix the reported EACCES scenario when directories already contain root-owned contents.
- Change is localized and straightforward, but using non-recursive `chown` can leave existing files/subdirectories with wrong ownership, so the primary bug may persist for common setups that have already run the container once as root-owned mounts.
- docker-setup.sh
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#5458: fix: set correct file ownership in Dockerfile (#5450)
by hakyonglee · 2026-01-31
85.9%
#3513: fix(docker): add MOLTBOT_STATE_DIR to resolve permission error
by Suksham-sharma · 2026-01-28
83.2%
#13737: Docker: harden UID/GID remap and docker-setup flow, convenience upd...
by ramarnat · 2026-02-10
83.1%
#6631: fix: configure npm global prefix for non-root user in Docker
by tjetzinger · 2026-02-01
81.8%
#11818: fix(docker): resolve build hang by using in-place ownership and opt...
by dilly · 2026-02-08
80.6%
#9999: Docker: fix token mismatch and add dev setup workflow
by benclarkeio · 2026-02-06
79.8%
#8376: Docker: inline chown to reduce image size and build time
by bugparty · 2026-02-03
79.3%
#13497: fix(docker): normalize workspace paths for container compatibility
by janckerchen · 2026-02-10
79.1%
#11576: Update Dockerfile, change file ownership during copy to prevent long …
by fastali · 2026-02-08
79.0%
#17506: Fix Entrypoint in docker-compose
by NeilSCGH · 2026-02-15
78.6%