【问题标题】:Reload .bashrc with Dockerfile使用 Dockerfile 重新加载 .bashrc
【发布时间】:2021-07-13 04:42:50
【问题描述】:

我创建了一个自定义别名来在 linux 中运行 powershell。为此,我创建了一个具有该别名的 docker 映像。但是当容器以该图像启动时,我的自定义别名无法按预期工作。我不得不使用source .bashrc 重新加载 .bashrc 然后它工作。我需要在 Dockerfile 中重新加载这个 .bashrc。非常感谢任何建议。

WORKDIR /home/releases
USER root

RUN   echo "alias powershell='pwsh'" >> .bashrc
#NTRYPOINT [ "bash","/opt/slave-launch.sh"]
RUN  apt-get update \
  && apt-get install -y wget \
  && rm -rf /var/lib/apt/lists/*
# Download the Microsoft repository GPG keys
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
RUN dpkg -i packages-microsoft-prod.deb

# Update the list of products
RUN apt-get update

# Install PowerShell
RUN apt-get install -y powershell

# Install Vim editor
RUN apt-get install vim -y

RUN source /etc/.bashrc

#ENTRYPOINT [ "bash","-c","sleep 2000"]
ENTRYPOINT [ "bash","/opt/slave-launch.sh"]

【问题讨论】:

标签: linux bash ubuntu dockerfile


【解决方案1】:

我认为您的问题是您在 /home/releases 下创建了一个 .bashrc 文件,但您使用的是 root 用户。当 root 用户启动 bash 程序时,源文件是 /root/.bashrc,而不是 /home/releases/.bashrc

要么创建一个非 root 的“发布”用户,要么将你的别名移动到 root .bashrc

【讨论】:

    【解决方案2】:

    你需要

    1. 了解在 Docker 容器中运行的用户
    2. 检查它的权限(它们必须是正确的,即 Docker 内的用户必须有权访问 .bashrc)
    3. 使用绝对路径.bashrc(即/home/user/.bashrc)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-28
      • 2015-02-26
      • 2012-04-06
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多