一、制作openjdk8基础镜像【基于自定义alpine-3.18.0:v1 】
docker pull maven:3.5.0-jdk-8-alpine
78.56 MB
https://hub.docker.com/_/maven/tags?page=8&name=alpine
openjdk二进制下载地址
https://blog.csdn.net/fenglllle/article/details/124786948
https://adoptopenjdk.net/releases.html
Dockerfile中,source /etc/profile不能加载的原因
为什么还需要选择使用他的原因:三 中,tomcat普通用户交互式启动tomcat
#在 Docker 容器中,/etc/profile 文件不会在容器启动时自动执行,这是因为 Docker 容器通常不会启动交互式登录 shell,而是直接运行指定的命令。/etc/profile 和用户的 shell 配置文件(如 .bash_profile[root]、.bashrc[普通用户] 等)是在交互式登录 shell 中被加载的。如果容器启动命令不涉及启动一个交互式 shell,这些文件就不会被执行。
解决方法
如果你需要在 Docker 容器中自动加载 /etc/profile 或其他环境配置,你可以采取以下几种方法之一:
1. 修改容器的启动命令
确保容器启动时使用交互式 shell。例如,你可以在 Dockerfile 中设置 CMD 或 ENTRYPOINT 指令来启动一个 Bash shell:
这样,当你以交互式方式运行容器时(使用 docker run -it <image>),它将启动 Bash,该 Bash 会加载 /etc/profile。
2. 在 Dockerfile 中使用环境变量
对于一些简单的环境设置,你也可以直接在 Dockerfile 中使用 ENV 指令来设置环境变量,这样就不需要依赖 /etc/profile
root@ubuntu:~/system/openjdk# cat profile
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export PAGER=less
umask 022
# use nicer PS1 for bash and busybox ash
if [ -n "$BASH_VERSION" -o "$BB_ASH_VERSION" ]; then
PS1='\h:\w\$ '
# use nicer PS1 for zsh
elif [ -n "$ZSH_VERSION" ]; then
PS1='%m:%~%# '
# set up fallback default PS1
else
: "${
HOSTNAME:=$(hostname)}"
PS1='${
HOSTNAME%%.*}:$PWD'
[ "$(id -u)" -eq 0 ] && PS1="${
PS1}# " || PS1