Files
docker/dockerfile/Dockerfile
2026-03-23 09:44:54 +08:00

19 lines
786 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 以普通用户运行,未测试
# 基础镜像以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)"]