我在 Dockerfile 中的 .bashrc 添加了很多东西,这是执行一些我想稍后在 Dockerfile 中运行的命令所必需的,
我尝试了 source .bashrc
但它不起作用。
我尝试使用 RUN/bin/bash -c --login ...
但出现错误:mesg: ttyname failed: inappropriate ioctl for device
最佳答案
Dockerfile 中的每个命令都会创建一个新的临时容器,但没有 tty(issue 1870,在 PR 4955 中讨论,但关闭以支持 PR 4882)。
docker 构建期间缺少 tty 会触发 ttyname failed: inappropriate ioctl for device
错误消息。
您可以尝试运行一个包装器脚本,其中将获取 .bashrc
。
Dockerfile
:
COPY myscript /path/to/myscript
RUN /path/to/myscript
我的脚本
:
#!/bin/bash
source /path/to/.bashrc
# rest of the commands
In my case it was for
nvm
: it adds aninit
script to.bashrc
therefore it wasn't usable in the Dockerfile context.
Ended up making an install script with it's dependent command.
关于bash - 如何在 dockerfile 中重新加载 .bashrc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50778021/