From d3b9e76aeb20652f705dec10707da490467b8aa3 Mon Sep 17 00:00:00 2001 From: daniel <48235622+1024daniel@users.noreply.github.com> Date: Mon, 30 Dec 2024 21:29:52 +0800 Subject: [PATCH] =?UTF-8?q?Add=20content=20src/site/notes/CloudNative/dock?= =?UTF-8?q?er/docker=20build/=E6=9B=B4=E6=94=B9=E5=9F=BA=E7=A1=80=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E7=94=A8=E6=88=B7id.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\345\203\217\347\224\250\346\210\267id.md" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "src/site/notes/CloudNative/docker/docker build/\346\233\264\346\224\271\345\237\272\347\241\200\351\225\234\345\203\217\347\224\250\346\210\267id.md" diff --git "a/src/site/notes/CloudNative/docker/docker build/\346\233\264\346\224\271\345\237\272\347\241\200\351\225\234\345\203\217\347\224\250\346\210\267id.md" "b/src/site/notes/CloudNative/docker/docker build/\346\233\264\346\224\271\345\237\272\347\241\200\351\225\234\345\203\217\347\224\250\346\210\267id.md" new file mode 100644 index 0000000..a7732a3 --- /dev/null +++ "b/src/site/notes/CloudNative/docker/docker build/\346\233\264\346\224\271\345\237\272\347\241\200\351\225\234\345\203\217\347\224\250\346\210\267id.md" @@ -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 + +# 继续其他构建步骤 + +``` \ No newline at end of file