【问题标题】:Source bash profile when starting interactive Docker session启动交互式 Docker 会话时的源 bash 配置文件
【发布时间】:2019-04-14 14:59:33
【问题描述】:

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

docker exec -it bash

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

【问题讨论】:

  • 你的意思是 your .bash_profile,还是从图像实例化的容器中的那个?
  • 容器中的那个。
  • bash -l 启动一个登录外壳(来源 .bash_profile); bash -i 启动一个交互式 shell(它的来源是 .bashrc)。

标签: bash docker exec


【解决方案1】:

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

docker exec -it bash -l

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-03-28
      • 1970-01-01
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      相关资源
      最近更新 更多