简体   繁体   English

如何以 tcsh 作为 shell 而不是 Bash 运行基于 linux 的 docker 容器?

[英]How do I run the linux based docker container with tcsh as the shell instead of Bash?

Here is the Dockerfile I am using with my goals specified within comment lines.这是我正在使用的 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

My interpretation ofhttps://github.com/moby/moby/issues/7281#issuecomment-389440503 is that the SHELL docker command should cause tcsh to be the default shell when I actually run a container based on the produced image.我对https://github.com/moby/moby/issues/7281#issuecomment-389440503的解释是,当我基于生成的图像实际运行容器时,SHELL docker 命令应该使 tcsh 成为默认 shell。 Here is some command line output.这是一些命令行输出。 After the image is built and a container is launched the default shell within the container is clearly still the bash shell.构建映像并启动容器后,容器内的默认 shell 显然仍然是 bash shell。 My interpretation was obviously wrong.我的解释显然是错误的。 How can I build the image such that the docker run command creates a container from the image where tcsh is the default instead of bash?如何构建映像,以便 docker run 命令从映像创建容器,其中 tcsh 是默认值而不是 bash? I have also tried to include 'chsh -s /bin/tcsh' as part of the RUN layer which did not work.我还尝试将 'chsh -s /bin/tcsh' 作为 RUN 层的一部分,但它不起作用。 Regardless of what I do the container always starts up running the bash shell, and the only way to cause tcsh to execute is by manually running a container interactively.无论我做什么,容器总是启动运行 bash shell,而使 tcsh 执行的唯一方法是手动交互地运行容器。 I need the container to start with tcsh as the shell so that environment scripts in csh can be executed.我需要容器以 tcsh 作为 shell 开始,以便可以执行 csh 中的环境脚本。

 > $docker build -t centos-csh:v5 . Sending build context to Docker daemon 2.048kB Step 1/3 : FROM centos:7 ---> eeb6ee3f44bd Step 2/3 : RUN set -e; echo "# Install dependencies"; yum -y install csh --disablerepo="*" --enablerepo="base"; ---> Using cache ---> 84b2f94f244c Step 3/3 : SHELL ["/bin/tcsh", "-c"] ---> Running in 3042be550a34 Removing intermediate container 3042be550a34 ---> 92d64253effe Successfully built 92d64253effe Successfully tagged centos-csh:v5 $winpty docker run -it --name csh-5 centos-csh:v5 [root@cfdb0280c39c /]# ps PID TTY TIME CMD 1 pts/0 00:00:00 bash 16 pts/0 00:00:00 ps

You should use ENTRYPOINT and not SHELL .您应该使用ENTRYPOINT而不是SHELL

Your Dockerfile should be like this:你的 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

However if you are using RUN in the Dockerfile after SHELL it will be running with tcsh.但是,如果您在SHELL之后在 Dockerfile 中使用RUN ,它将使用 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

So SHELL is for the RUN during the build and ENTRYPOINT if for when you are using docker run ...所以SHELL用于构建期间的RUNENTRYPOINT如果您使用 docker docker run ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM