skip to Main Content

What I would like to accomplish.

I have a centos container in Docker and am trying to change the shell to ksh using the following Dockerfile and command, but it appears to be sh.

Expected behavior.

echo ${SHELL}
/bin/ksh

Current behavior

echo ${SHELL}
/bin/sh

I don’t know the cause of the problem, and I don’t know how to solve it.
I would appreciate it if someone could tell me what is going on.

Dockerfile & Command

Dockerfile

FROM centos:centos7

RUN yum install ksh -y
RUN chsh -s /bin/ksh root

CMD ["/bin/ksh"].

build

docker build -t mybashimage .
[+] Building 33.5s (7/7) FINISHED
 => [internal] load build definition from Dockerfile 0.0s
 => => transferring dockerfile: 129B 0.0s
 => [internal] load .dockerignore 0.0s
 => => transferring context: 2B 0.0s
 => [internal] load metadata for docker.io/library/centos:centos7 0.0s
 => CACHED [1/3] FROM docker.io/library/centos:centos7 0.0s
 => [2/3] RUN yum install ksh -y 31.5s
 => [3/3] RUN chsh -s /bin/ksh root 0.4s
 => exporting to image 1.6s
 => => exporting layers 1.6s
 => => writing image sha256:ffefefa6641e2cb21bd90aec5b257c130ade5bb11d02cd7604d6a3c7baf2be10 0.0s
 => => naming to docker.io/library/mybashimage

Launching containers.

docker run -it --rm mybashimage:latest

Check the shell.

echo ${SHELL}
/bin/sh

What I tried

user (root) shell has changed => root’s shell was changed to /bin/ksh

head /etc/passwd
root:x:0:0:root:/root:/bin/ksh
bin:x:1:1:bin:/bin:/sbin/nologin

Confirm login user.

whoami
root

Check shells

# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/ksh
/bin/rksh

Check shell

# ps -p $$
  PID TTY          TIME CMD
    1 pts/0    00:00:00 ksh

Purpose of this question

The purpose was to create a ksh environment for the shell. Since my own Mac has zsh and I did not want to touch it, I used docker.
I believed that echo ${SHELL} would show me information about the shell I was currently using, so I used echo ${SHELL} to check the shell, but /bin/sh was displayed and I was worried that /bin/ksh was really being used. That is why I asked this question.

2

Answers


  1. Chosen as BEST ANSWER

    I just created a testuser and changed it to ksh and now I get /bin/ksh with echo ${SHELL}.


  2. ${SHELL} is not a reliable source to check your current running shell. use ${$} instead.
    and your comment about TIME, that’s normal since it is not using any cpu time.

    if You want to change the time run a command that uses cpu and check it from another terminal like:
    shell 1:

    echo ${$}
    
    # copy shell pid
    
    while : ; do echo hi ; done
    

    shell 2:

    ps -Fp ${shell_pid}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search