How to change the default /bin/sh to /bin/bash on opening CLI for selected container in Docker Desktop?

Viewed 3149

If I select any container and click CLI button, the /bin/sh shell will be opened by default. Is there any way to manually reconfigure Docker to open /bin/bash?

3 Answers

Not exactly answer you asked for but for me it works to type bash in sh terminal. It opens bash over the sh. Only nousance is that I must exit twice.

It will depend on the base image, you can build a custom image and add bash if it is not available. And link the create a link to use bash instead of sh

FROM <BASE_IMAGE>
RUN apk add --no-cache bash

RUN ln -sf /bin/bash /bin/sh

I changed default shell into bash by making a new image with below Dockerfile commands.

# Dockerfile
FROM <parent image>

# make /bin/sh symlink to bash instead of dash:
RUN echo "dash dash/sh boolean false" | debconf-set-selections
RUN DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash

# set ENV to execute startup scripts
ENV ENV ~/.profile

and create a new image.

$ docker build --tag <image> .
  1. change symbolic link of /bin/sh to bash

    https://superuser.com/questions/715722/how-to-do-dpkg-reconfigure-dash-as-bash-automatically

  2. source ~/.profile file when executing /bin/sh

    Is there an alternative for .bashrc for /bin/sh?

  3. If you want to clear ENV after startup, you may add below line to the ~/.bashrc file. (Be careful not to mess up other scripts)

    unset ENV
    
Related