[GH-ISSUE #3625] [Feature request] Support for running as non-root user in docker installation #2433

Closed
opened 2026-10-31 20:25:28 +07:00 by bsakaguchi · 7 comments
Owner

Originally created by @janusn on GitHub (Jan 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/3625

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 user directive in compose.yaml

Describe alternatives you've considered

No response

Checklist

  • This feature report is written entirely in English.
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 `user` directive in `compose.yaml` ### Describe alternatives you've considered _No response_ ### Checklist - [x] This feature report is written entirely in English.
bsakaguchi 2026-10-31 20:25:28 +07:00
Author
Owner

@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 enable userns-remap protection for such a container.

@MHSanaei , take this into consideration, please.

<!-- gh-comment-id:3958843781 --> @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 enable `userns-remap` protection for such a container. @MHSanaei , take this into consideration, please.
Author
Owner

@MahouShoujoMivutilde commented on GitHub (May 26, 2026):

You don't need to run network_mode: host.

Instead add

# in compose file
    ports:
      # panel
      - "127.0.0.1:2053:2053"
      # xray
      - "443:443"

and

// /etc/docker/daemon.json 
{
// ....
  "userns-remap": "default"
}
systemctl daemon-reload

systemctl restart docker.service

After that you'd need to docker compose pull, docker compose up -d again, and

chown -R all files inside volumes to the new user id, which you can see in htop for x-ui process, or in /etc/subuid and in /etc/subgid for the user dockremap. 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 db

And 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: host is asking for trouble.

<!-- gh-comment-id:4547010823 --> @MahouShoujoMivutilde commented on GitHub (May 26, 2026): You don't need to run `network_mode: host`. Instead add ```yaml # in compose file ports: # panel - "127.0.0.1:2053:2053" # xray - "443:443" ``` and ```jsonc // /etc/docker/daemon.json { // .... "userns-remap": "default" } ``` ```bash systemctl daemon-reload systemctl restart docker.service ``` After that you'd need to `docker compose pull`, `docker compose up -d` again, and `chown -R` all files inside volumes to the new user id, which you can see in htop for x-ui process, or in `/etc/subuid` and in `/etc/subgid` for the user `dockremap`. 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 db` And 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: host` is asking for trouble.
Author
Owner

@Anderhar commented on GitHub (May 26, 2026):

You don't need to run network_mode: host.

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.

<!-- gh-comment-id:4547919251 --> @Anderhar commented on GitHub (May 26, 2026): > You don't need to run `network_mode: host`. 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.
Author
Owner

@janusn commented on GitHub (May 27, 2026):

chown -R all files inside volumes to the new user id, which you can see in htop for x-ui process, or in /etc/subuid and in /etc/subgid for the user dockremap. 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 db

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 -R all files inside volumes to the new user id"? Does it mean the all files and directories of /etc/x-ui and '/var/log/`? Are there more to be taken care of?

<!-- gh-comment-id:4552895280 --> @janusn commented on GitHub (May 27, 2026): > `chown -R` all files inside volumes to the new user id, which you can see in htop for x-ui process, or in `/etc/subuid` and in `/etc/subgid` for the user `dockremap`. 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 db` > 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 -R` all files inside volumes to the new user id"? Does it mean the all files and directories of `/etc/x-ui` and '/var/log/`? Are there more to be taken care of?
Author
Owner

@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:

    volumes:
      - ./db/:/etc/x-ui/
      - ./log/:/var/log/
      - ./cert/:/root/cert/

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-remap the root inside the container now is user id and group id of 100000, these files would be readable, assuming default permissions, but not writable - because as far as the host concerned, they are read with uid gid 100000, 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 be chown'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 cert from root, for the volumes example above.

<!-- gh-comment-id:4559818728 --> @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: ```yaml volumes: - ./db/:/etc/x-ui/ - ./log/:/var/log/ - ./cert/:/root/cert/ ``` 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-remap` the root inside the container now is user id and group id of `100000`, these files would be readable, assuming default permissions, but not writable - because as far as the host concerned, they are read with uid gid `100000`, 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 be `chown`'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 cert` from root, for the volumes example above.
Author
Owner

@Anderhar commented on GitHub (May 28, 2026):

@MahouShoujoMivutilde , that's not quite right.

anything that was exposed to the host via volumes

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.yaml would look something like this in that case:

services:
  3xui:
    volumes:
      - db:/etc/x-ui
      - log:/var/log
      - ./cert/:/root/cert:ro

volumes:
  db:
  log: 

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.

Second, if the binded directory/file doesn’t exist, it will be created during the first launch of the container with 100000:100000 ownership, so you don’t need to chown in 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 :rw access (applied by default). I actually hate this behavior, but that's how things work.

Personally, I never use chown and have never even had the need to. The dockremap user should automate these kinds of things.

<!-- gh-comment-id:4562387380 --> @Anderhar commented on GitHub (May 28, 2026): @MahouShoujoMivutilde , that's not quite right. > anything that was exposed to the host via volumes 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.yaml` would look something like this in that case: ``` services: 3xui: volumes: - db:/etc/x-ui - log:/var/log - ./cert/:/root/cert:ro volumes: db: log: ``` > 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. Second, if the **binded** directory/file doesn’t exist, it will be created during the first launch of the container with `100000:100000` ownership, so you don’t need to `chown` in 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 `:rw` access (applied by default). I actually hate this behavior, but that's how things work. Personally, I never use `chown` and have never even had the need to. The dockremap user should automate these kinds of things.
Author
Owner

@janusn commented on GitHub (May 28, 2026):

I have looked up what userns-remap does. It affects every container in the docker. I need more time and effort to study it.

Thanks for enlighten me.

<!-- gh-comment-id:4568028657 --> @janusn commented on GitHub (May 28, 2026): I have looked up what `userns-remap` does. It affects every container in the docker. I need more time and effort to study it. Thanks for enlighten me.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#2433
No description provided.