简体   繁体   中英

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.

# 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. 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. 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? I have also tried to include 'chsh -s /bin/tcsh' as part of the RUN layer which did not work. 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. I need the container to start with tcsh as the shell so that environment scripts in csh can be executed.

 > $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 .

Your Dockerfile should be like this:

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.

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 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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