Mapping UIDs for Rootless Podman DevContainers
Under rootless Podman, files a container writes to your workspace can land owned by a subordinate UID instead of you. This page fixes that with the keep-id user-namespace mapping, so container writes stay owned by your host user and Git keeps working.
Prerequisites
You need rootless Podman with subuid/subgid ranges configured.
- Podman running rootless (
podman infoas your user). /etc/subuidand/etc/subgidwith a range for your user.- A devcontainer you can add
runArgsto.
Step-by-Step Implementation
- Confirm your subordinate ID range exists.
grep "^$USER:" /etc/subuid /etc/subgid
- Add the keep-id userns mapping so the container user maps to your host UID.
{
"runArgs": ["--userns=keep-id"],
"remoteUser": "vscode"
}
- Rebuild and let Podman apply the mapping.
devcontainer up --workspace-folder . --remove-existing-container
- Verify a container-created file is owned by you.
devcontainer exec --workspace-folder . -- touch /workspace/.owncheck && stat -c '%U' .owncheck
Common Pitfalls
Ownership problems under rootless are almost always a missing or wrong userns mapping.
| Symptom | Root Cause | Remediation |
|---|---|---|
| Files owned by a high subuid | No keep-id mapping | Add --userns=keep-id to runArgs |
| keep-id has no effect | subuid range too small | Widen the subuid/subgid range |
| Permission denied on mount | Container UID can't write | Align remoteUser UID with keep-id |
| Works rootful, not rootless | Assumed root daemon behaviour | Use keep-id under rootless |
Conclusion
Rootless ownership comes down to one option: --userns=keep-id maps the container user to your host UID, so everything it writes to the workspace stays yours. Confirm your subuid range covers it, and bind-mount ownership stops being a rootless headache.
FAQ
What does --userns=keep-id actually do? It maps the container's user to your host user's UID/GID directly, instead of into a subordinate range. So a file the container writes to a bind-mounted workspace is owned by your host user, keeping Git and host tooling happy.
Why are my files owned by a huge UID like 100999?
That is a subordinate UID from your /etc/subuid range — the default rootless mapping. Add --userns=keep-id so the container user maps to your real UID instead, and new files are owned by you.
Do I still need remoteUser with keep-id?
Yes. remoteUser selects which container user runs, and keep-id maps that user to your host UID. Together they ensure the process runs as a non-root user that also owns workspace files correctly on the host.
Related
- Up to Podman & Rootless Container Engines — the overview of rootless engines.
- Using podman-compose in a DevContainer — multi-service rootless stacks.
- Migrating from Docker to Podman in DevContainers — switching engines.