如果我选择任何一个容器并点击 CLI 按钮,则默认打开 /bin/sh
shell。有没有办法手动重新配置 Docker 以打开 /bin/bash
?
如果我选择任何一个容器并点击 CLI 按钮,则默认打开 /bin/sh
shell。有没有办法手动重新配置 Docker 以打开 /bin/bash
?
这将取决于基础镜像,如果没有bash可用,则可以构建自定义镜像并添加bash。然后创建一个链接以使用bash而不是sh。
FROM <BASE_IMAGE>
RUN apk add --no-cache bash
RUN ln -sf /bin/bash /bin/sh
虽然不完全回答了你的问题,但对我而言,在sh终端中键入bash
就可以打开sh上的bash。唯一的麻烦是我必须要两次输入exit
。
我通过使用以下Dockerfile
命令创建一个新的镜像,将默认shell更改为bash
。
# 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
并创建一个新图像。
$ docker build --tag <image> .
change symbolic link of /bin/sh
to bash
https://superuser.com/questions/715722/how-to-do-dpkg-reconfigure-dash-as-bash-automatically
source ~/.profile
file when executing /bin/sh
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
docker exec -it CONTAINER_NAME bash
。 - anemyte