启动交互式 Docker 会话时的来源 bash 配置文件

Source bash profile when starting interactive Docker session

运行 这将以交互方式打开 bash:

docker exec -it bash

但是,它不是采购 ~/.bash_profile,即容器中的 bash_profile。我在最后尝试了 bash -i 而不是 bash,但没有用。那么如何在进入容器时加载配置文件,就像在常规交互中一样 shell?

将此添加到容器用户 .bashrc:

if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile
fi

您需要重建映像并复制 .bash_profile 文件。

-l 有效,正如@chepner 在评论中提到的那样:

docker exec -it bash -l