bash - 如何在 dockerfile 中重新加载 .bashrc

标签 bash docker dockerfile

我在 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    

Abderrahim指出in the comments :

In my case it was for nvm: it adds an init 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/

相关文章:

bash:在循环中 curl 并行请求

string - 线路操作和排序

linux - 用于验证Linux上make版本的Shell脚本

node.js - W : Failed to fetch http://deb. debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 未找到 [IP : 151. 101.140.204 80]

mongodb - 如何填写 Docker mongodb 镜像

docker - Dockerfile MKDIR不起作用(node:alpine)

linux - 如何在 bash 循环中回显参数

c# - 在 docker 容器异常 : Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl' 中运行的身份服务器 4

在 docker 中分离运行时,Python 应用程序不打印任何内容

docker - 让 docker-compose 构建使用父容器的容器