下面是我在注释行中指定的目标中使用的Dockerfile。
# Goal is to install dependencies such as csh and then
# finish building an image where tcsh is the default shell
# within the container.
FROM centos:7
RUN set -e; \
echo "# Install DRS dependencies csh and libjpeg"; \
yum -y install csh --disablerepo="*" --enablerepo="base"; \
# Setting the default shell of the user did not work either
# chsh -s /bin/tcsh;
SHELL ["/bin/tcsh", "-c"]
# I need to subsequently run csh scripts without having to
# manually logon to the container, run tcsh, and then manually
# launch the script. The application within the container
# is a native C++ application that relies on environment
# variables set by a complex csh script
# Regardless of what I have tried, the shell running when the
# container launches is always bash我对https://github.com/moby/moby/issues/7281#issuecomment-389440503的解释是,当我根据生成的映像实际运行容器时,SHELL停靠器命令应该使tcsh成为默认的shell。下面是一些命令行输出。在构建映像并启动容器之后,容器中的默认shell显然仍然是bash。我的解释显然是错误的。如何构建映像,使docker命令从默认的映像中创建容器,而不是bash?我还尝试将'chsh -s /bin/tcsh‘作为运行层的一部分,但没有工作。不管我做什么,容器总是启动运行bash,而使tcsh执行的唯一方法是交互地手动运行容器。我需要容器以tcsh作为shell开始,以便能够执行csh中的环境脚本。
$docker build -t centos-csh:v5。将构建上下文发送到Docker 2.048kB步骤1/3 :从centos:7 -> eeb6ee3f44bd步骤2/3 :运行set -e;回显"#安装依赖关系“;yum -y安装csh --disablerepo="*”-enablerepo=“base”;->使用缓存--> 84b2f94f244c步骤3/3 : SHELL "/bin/tcsh","-c“-->在3042be550a34中运行,删除中间容器3042be550a34 -> 92d64253effe成功构建了92d64253effe成功标记中心-csh:v5 $winpty docker运行-it --名称csh-5 centos-csh:v5 root@cfdb0280c39c /# PID TTY TIME CMD 1/0/ 00:00:00 bash 16 pts/0 00:00:00 ps
发布于 2022-06-30 16:59:09
您应该使用入口点,而不是SHELL。
您的Dockerfile应该是这样的:
FROM centos:7
RUN set -e; \
yum -y install csh --disablerepo="*" --enablerepo="base"
ENTRYPOINT ["/bin/tcsh"]$ docker build -t centos-tcsh .
$ docker run -it --rm centos-tcsh
[root@0d427444c2e4 /]# ps
PID TTY TIME CMD
1 pts/0 00:00:00 tcsh
21 pts/0 00:00:00 ps但是,如果您在Dockerfile中使用,在SHELL之后运行,那么它将与tcsh一起运行。
FROM centos:7
RUN set -e; \
yum -y install csh --disablerepo="*" --enablerepo="base"
SHELL ["/bin/tcsh", "-c"]
RUN ps -A$ docker build -t centos-tcsh .
[...]
Step 3/5 : SHELL ["/bin/tcsh", "-c"]
---> Running in f22514d13cca
Removing intermediate container f22514d13cca
---> e5a10966d0a1
Step 4/5 : RUN ps -A
---> Running in 0eaa2996c4ff
PID TTY TIME CMD
1 ? 00:00:00 tcsh
12 ? 00:00:00 ps
Removing intermediate container 0eaa2996c4ff
[...]
$ docker run -it --rm centos-tcsh
[root@81df5c8b3061 /]# ps -A
PID TTY TIME CMD
1 pts/0 00:00:00 bash
15 pts/0 00:00:00 ps因此,SHELL用于运行,如果您使用docker run ...,则用于构建和入口点。
https://stackoverflow.com/questions/72819074
复制相似问题