default shell if "-it " option is used

Hi, 
What is the difference in the following 3 containers instances ?

[root@eilagcy1 user]# docker run -it --name tstps7 centos:7 /bin/bash

[root@9a0b46597830 /]# ps

PID TTY TIME CMD

1 ? 00:00:00 bash  ---> Should here be 2 bash processes running? 

13 ? 00:00:00 ps

[root@9a0b46597830 /]# exit

exit

[root@eilagcy1 user]# docker run -it --name tstps8 centos:7

[root@075aa090c49e /]# ps

PID TTY TIME CMD

1 ? 00:00:00 bash

13 ? 00:00:00 ps

[root@075aa090c49e /]# exit

exit

[root@eilagcy1 user]# docker run -it --name tstps9 centos:7 /bin/sh

sh-4.2# ps

PID TTY TIME CMD

1 ? 00:00:00 sh  --> sh is running instead of bash

    5 ? 00:00:00 ps


#####
I want to understand if I use the options -it and does not pass any command ( like example2 above) , is it that the container instance will run a bash shell instance always?  if yes, then should there be 2 instances of bash running  ( if i use -it options and pass command /bin/bash to container run)

please clarify

Regards,
Anuraag 


  • post-author-pic
    Keith T
    12-10-2018

    If you don't specify a command then the docker run command will run whatever the CMD is for the image. In this case, the Dockerfile for the CentOS 7 sets the CMD to `/bin/bash`. Passing the `-it` flags does not change the command that is being run. If you do specify a command when starting the container it will override the default CMD instead of running both processes.


    Hopefully, that makes things more clear.

Looking For Team Training?

Learn More