首页 > 解决方案 > 启动交互式 Docker 会话时的源 bash 配置文件

问题描述

运行它以交互方式打开 bash:

docker exec -it bash

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

标签: bashdockerexec

解决方案


将此添加到容器用户.bashrc

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

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


推荐阅读