-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content src/site/notes/CloudNative/docker/docker build/更改基础镜像用户id.md
- Loading branch information
1 parent
f2dd618
commit d3b9e76
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/site/notes/CloudNative/docker/docker build/更改基础镜像用户id.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
{"dg-publish":true,"permalink":"/CloudNative/docker/docker build/更改基础镜像用户id/","noteIcon":"3"} | ||
--- | ||
|
||
#dockerfile #docker | ||
```dockerfile | ||
# 使用基础镜像 | ||
FROM base-image:latest | ||
|
||
# 切换到 root 用户 | ||
USER root | ||
|
||
# 修改用户和组的 UID 和 GID | ||
RUN groupmod -g 1001 HwHiAiUser && \ | ||
usermod -u 1001 -g 1001 HwHiAiUser | ||
|
||
# 修复整个文件系统中属于旧 UID/GID 的文件权限 | ||
RUN find / -path /proc -prune -o -user 1000 -exec chown -h 1001 {} + && \ | ||
find / -path /proc -prune -o -group 1000 -exec chgrp -h 1001 {} + | ||
|
||
# 切换回非 root 用户(如果需要) | ||
USER HwHiAiUser | ||
|
||
# 继续其他构建步骤 | ||
|
||
``` |