提交dockerfile

This commit is contained in:
2026-03-23 09:44:54 +08:00
commit 834242bb7e
11 changed files with 194 additions and 0 deletions

19
dockerfile/Dockerfile Normal file
View File

@@ -0,0 +1,19 @@
# 以普通用户运行,未测试
# 基础镜像以ubuntu为例其他镜像如alpine、centos逻辑一致
FROM ubuntu:22.04
# 1. 创建普通用户指定UID/GID避免权限冲突可选但推荐
# -m创建家目录-s指定shell--uid/--gid指定固定ID
RUN groupadd --gid 1001 appgroup && \
useradd --uid 1001 --gid appgroup --create-home --shell /bin/bash appuser
# 2. (可选)设置工作目录并修改权限(确保普通用户可读写)
WORKDIR /app
RUN chown -R appuser:appgroup /app
# 3. 切换到普通用户(关键:后续所有命令都以该用户执行)
USER appuser
# 4. 以普通用户运行CMD/ENTRYPOINT
# 示例:执行一个简单的脚本或应用
CMD ["echo", "当前用户:$(whoami),工作目录:$(pwd)"]