Skip to content

Support running container as non-root user#60

Merged
jasonmadigan merged 2 commits into
mainfrom
50-non-root-docker
Jun 3, 2026
Merged

Support running container as non-root user#60
jasonmadigan merged 2 commits into
mainfrom
50-non-root-docker

Conversation

@jasonmadigan

Copy link
Copy Markdown
Collaborator

Summary

Makes the Docker container work with --user "$(id -u):$(id -g)" so mounted volume files are owned by the host user instead of root.

Closes #50

Changes

  • Add tracefinity user (UID 1000) as default non-root user
  • Move nginx/supervisord pid and log files to /tmp/ (writable without root)
  • Remove user www-data directive from nginx config
  • Add docker-entrypoint.sh that creates required runtime directories at startup
  • Set writable permissions on all runtime directories for arbitrary UID support
  • Set U2NET_HOME=/app/.u2net and HOME=/app for model downloads

How it works

  • Default: container runs as tracefinity (UID 1000) — no --user needed
  • With --user: works with any UID because runtime dirs are world-writable (standard pattern for arbitrary UID containers, same as OpenShift S2I images)
  • Backwards compatible: existing docker run commands without --user still work

Test plan

  • Docker image builds successfully (21/21 steps)
  • Verified default user: uid=1000(tracefinity)
  • Verified arbitrary UID: --user 501 works, all runtime dirs writable
  • Entrypoint creates required dirs on first run, warns on failure

Create a tracefinity user (UID 1000) that runs by default. The container
also works with arbitrary UIDs via --user "$(id -u):$(id -g)" so mounted
volume files are owned by the host user instead of root.

Changes:
- Add docker-entrypoint.sh for runtime directory creation
- Create non-root tracefinity user, default to it via USER
- Move nginx pid to /tmp/nginx, remove user directive
- Move supervisord pid/logs to /tmp/supervisor
- Set U2NET_HOME=/app/.u2net so rembg model cache is writable
- Set HOME=/app so ~ resolves to a writable path
- chmod 777 all runtime-writable directories for arbitrary UID support
- Update README with --user example
- Document non-root setup in docs/gotchas.md

Signed-off-by: Jason Madigan <[email protected]>
@jasonmadigan
jasonmadigan marked this pull request as ready for review June 3, 2026 15:46
@jasonmadigan
jasonmadigan merged commit e89fe9f into main Jun 3, 2026
1 check passed
@jasonmadigan
jasonmadigan deleted the 50-non-root-docker branch June 14, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support running the software in the docker container as non-root user

1 participant