mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #3625] [Feature request] Support for running as non-root user in docker installation #2433
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#2433
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @janusn on GitHub (Jan 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/3625
Is your feature request related to a problem?
Running as root in docker installation increases the attack vectors.
Describe the solution you'd like
An option to run as a non-root user in docker installation.
For example, adding a support of
userdirective incompose.yamlDescribe alternatives you've considered
No response
Checklist
@Anderhar commented on GitHub (Feb 25, 2026):
Totally agree!
Root user paired with
network_mode: host– that's ouch... Taken seperately, these two aren't a big deal, but when combined, you can't even enableuserns-remapprotection for such a container.@MHSanaei , take this into consideration, please.
@MahouShoujoMivutilde commented on GitHub (May 26, 2026):
You don't need to run
network_mode: host.Instead add
and
After that you'd need to
docker compose pull,docker compose up -dagain, andchown -Rall files inside volumes to the new user id, which you can see in htop for x-ui process, or in/etc/subuidand in/etc/subgidfor the userdockremap. Make sure range doesn't overlap with existing users. First number is the start of the range, second is the number of ids allocated for the user starting from that range.It'll probably be
chown -R 100000:100000 dbAnd after that in your inbound settings, Stream - enable External Proxy, in its fields set "same", your external vps IP, your external xray port (443), some note. This will make qr codes use the correct address.
This doesn't cover subscription service at all, though.
But you're right, you shouldn't need to do this, and running everything as root with
network_mode: hostis asking for trouble.@Anderhar commented on GitHub (May 26, 2026):
Right, I was just about to comment that the latest versions don't need the host network to run. I haven't done a full round of testing yet, but now the 3X-UI container attached to bridge network starts up without any errors.
@janusn commented on GitHub (May 27, 2026):
First of all. Let me thank you for helping me and other out. A big salute from me. 👏🏻👏🏻👏🏻
I am still a bit lost though. Could you please elaborate on "
chown -Rall files inside volumes to the new user id"? Does it mean the all files and directories of/etc/x-uiand '/var/log/`? Are there more to be taken care of?@MahouShoujoMivutilde commented on GitHub (May 28, 2026):
Yes, anything that was exposed to the host via volumes would need to have its ownership updated to match the user id and group id the x-ui process is running from, as seen by the host, since the volumes are on the host.
Say, you have:
If you do
ls -lh ./db ./log ./cert, you'd see that all files are still owned by the real (outside of container) root.Since with
userns-remapthe root inside the container now is user id and group id of100000, these files would be readable, assuming default permissions, but not writable - because as far as the host concerned, they are read with uid gid100000, which isn't real root that still owns the files.That means x-ui inside the container can't write logs or update settings etc - it no longer owns these files.
So what we need to do, is to make it own them again.
Anything you had under
volumes, that is, any file & folder that was exposed from the container to the outside, should bechown'ed to match the new user and group id the x-ui is using.To do so, you can run
chown -R 100000:100000 db log certfrom root, for the volumes example above.@Anderhar commented on GitHub (May 28, 2026):
@MahouShoujoMivutilde , that's not quite right.
First, what you're using in your command aren't volumes – they're bindings. If you were actually using volumes, you wouldn't need any additional ownership manipulations, and
compose.yamlwould look something like this in that case:Second, if the binded directory/file doesn’t exist, it will be created during the first launch of the container with
100000:100000ownership, so you don’t need tochownin this case either.More than that, dockremap user can even change the ownership of existing folders if they currently owned by the unprivileged user and binded with
:rwaccess (applied by default). I actually hate this behavior, but that's how things work.Personally, I never use
chownand have never even had the need to. The dockremap user should automate these kinds of things.@janusn commented on GitHub (May 28, 2026):
I have looked up what
userns-remapdoes. It affects every container in the docker. I need more time and effort to study it.Thanks for enlighten me.