mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-26 03:35:31 +00:00
Add blank lines before headers
This commit is contained in:
@@ -61,6 +61,7 @@ CMD ["node", "server.js"]
|
||||
#### 使用 UID/GID
|
||||
|
||||
```docker
|
||||
|
||||
## 也可以使用数字
|
||||
|
||||
USER 1001:1001
|
||||
@@ -73,9 +74,11 @@ USER 1001:1001
|
||||
`USER` 指令只能切换到 **已存在** 的用户:
|
||||
|
||||
```docker
|
||||
|
||||
## ❌ 错误:用户不存在
|
||||
|
||||
USER nonexistent
|
||||
|
||||
## Error: unable to find user nonexistent
|
||||
|
||||
## ✅ 正确:先创建用户
|
||||
@@ -163,6 +166,7 @@ exec gosu redis "$@"
|
||||
使用 `-u` 或 `--user` 参数:
|
||||
|
||||
```bash
|
||||
|
||||
## 以指定用户运行
|
||||
|
||||
$ docker run -u 1001:1001 myimage
|
||||
@@ -208,6 +212,7 @@ CMD ["node", "server.js"]
|
||||
#### 1. 始终使用非 root 用户
|
||||
|
||||
```docker
|
||||
|
||||
## ✅ 推荐
|
||||
|
||||
RUN adduser -D appuser
|
||||
@@ -224,6 +229,7 @@ CMD ["myapp"] # 以 root 运行
|
||||
便于在宿主机和容器间共享文件:
|
||||
|
||||
```docker
|
||||
|
||||
## 使用常见的非 root UID
|
||||
|
||||
RUN addgroup -g 1000 -S appgroup && \
|
||||
@@ -234,6 +240,7 @@ USER 1000:1000
|
||||
#### 3. 多阶段构建中的 USER
|
||||
|
||||
```docker
|
||||
|
||||
## 构建阶段可以用 root
|
||||
|
||||
FROM node:20 AS builder
|
||||
|
||||
Reference in New Issue
Block a user