Skip to content

Commit 1d5d958

Browse files
committed
docs(nonroot): 更新非 root 用户下运行 Gowebdav 的文档说明
- 修改表述为更清晰的表达方式,如“wish to run”替代“want to use” - 增加创建数据目录及获取 UID/GID 的命令示例 - 调整 docker-compose 配置示例,使用 `/data` 作为容器内挂载点 - 更新环境变量中 dav 路径配置与挂载路径一致 - 强调提前创建目录的重要性以避免权限问题 - 简化注意事项,聚焦于用户权限与目录所有权的核心问题 Signed-off-by: 117503445 <t117503445@gmail.com>
1 parent 4a0a022 commit 1d5d958

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

doc/nonroot.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
# nonroot
22

3-
If you want to use Gowebdav with Docker under a non-root user, you can follow these steps.
3+
If you wish to run Gowebdav in Docker under a non-root user environment, please follow the steps below.
44

55
## Steps
66

7-
Using Docker Compose as an example, let's say you want to share `./data/dir1` and `./data/dir2` directories. First, prepare a `docker-compose.yml` file:
7+
Taking Docker Compose as an example, suppose you want to share two directories: `./data/dir1` and `./data/dir2`. First, prepare your directories:
8+
9+
```bash
10+
mkdir -p ./data # This is just an example; you can create directories in any way you prefer
11+
```
12+
13+
Next, obtain the UID and GID of the directory:
14+
15+
```bash
16+
ls -nd ./data | awk '{ print $3":"$4 }'
17+
```
18+
19+
Then, create a `docker-compose.yml` file:
820

921
```yaml
1022
services:
1123
go_webdav:
1224
image: 117503445/go_webdav
1325
restart: unless-stopped
1426
volumes:
15-
- ./data:/home/nonroot
27+
- ./data:/data
1628
environment:
17-
- "dav=/dir1,/home/nonroot/dir1,null,null,false;/dir2,/home/nonroot/dir2,null,null,false"
29+
- "dav=/dir1,/data/dir1,null,null,false;/dir2,/data/dir2,null,null,false"
1830
ports:
1931
- "80:80"
20-
user: "nonroot" # Specify the user inside the container as nonroot
21-
```
22-
23-
Next, create the directories and set the permissions to 777:
24-
25-
```bash
26-
mkdir -p ./data/dir1 ./data/dir2
27-
chmod 777 ./data/dir1 ./data/dir2
32+
user: "1000:1000" # Replace with the correct UID and GID to ensure execution under the proper user
2833
```
2934
3035
Finally, start the container:
@@ -35,10 +40,6 @@ docker compose up -d
3540

3641
## Notes
3742

38-
`117503445/go_webdav` is based on [gcr.io/distroless/static-debian12](https://github.com/GoogleContainerTools/distroless). The `nonroot` user inside the image is a non-root user with a UID of 65532 and has write permissions to the `/home/nonroot` directory.
39-
40-
- If you do not create the `data` directory in advance, it will be automatically created when the container starts. However, this will be done by the Docker Daemon with root privileges, which may lead to permission issues.
41-
- If you do not create the `dir1` and `dir2` directories in advance, they will be created by `GoWebdav` when the container starts. Since these directories will belong to the `nonroot` user, external regular users will not be able to write to them.
42-
- If you do not set the permissions to 777 in advance, the `nonroot` user in `GoWebdav` will not be able to write to these directories.
43-
44-
In the scenarios described above, both inside and outside the container are regular users. If you only require the container to run as a regular user and the host to run as root, or vice versa, the setup might be simpler.
43+
Docker supports specifying a user via the `--user "UID:GID"` option, allowing you to run containers as a non-root user.
44+
However, you must create the `data` directory in advance to prevent the Docker daemon from creating it with root permissions, which could lead to permission issues.
45+
In the scenario above, both inside and outside the container use a regular (non-root) user. If you only require the container to run as a regular user while the host uses root (or vice versa), the setup might be simpler.

0 commit comments

Comments
 (0)