【问题标题】:Not able to run source command from Dockerfile无法从 Dockerfile 运行源命令
【发布时间】:2019-01-28 22:08:56
【问题描述】:

这是 Dockerfile 中的脚本。当我直接进入 docker 并手动运行命令时,它工作正常,但为什么不能从 Dockerfile 中运行。

Dockerfile:

FROM ubuntu:16.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev
RUN apt-get install -y curl git sudo

RUN curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
RUN /bin/sh install_nvm.sh
RUN source ~/.profile

错误:

mesg: ttyname failed: 设备的 ioctl 不合适

我已经尝试了一些解决方案,比如运行它 RUN /bin/sh -c "source ~/.profile" 和其他一些但没有解决问题。

【问题讨论】:

标签: docker dockerfile


【解决方案1】:

尝试用以下命令替换您的命令。 RUN /bin/bash -c "source ~/.profile"

【讨论】:

  • 无论 /bin/sh 还是 /bin/bash 都一样
【解决方案2】:

这与这个问题非常相似:How to solve 'ttyname failed: Inappropriate ioctl for device' in Vagrant?

~/.profile中有一行:

mesg n || true

这是不兼容的。为了修复它,以 tty 是否可用 (credit Gogowitsch) 为条件:

RUN sed -i ~/.profile -e 's/mesg n || true/tty -s \&\& mesg n/g'

此 sed 命令将 mesg n || true 替换为 tty -s && mesg n(尝试它,如果失败则忽略),(仅在成功时尝试)这会使错误消息消失

【讨论】:

    猜你喜欢
    • 2017-11-12
    • 2019-11-08
    • 2022-01-18
    • 2019-07-17
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    相关资源
    最近更新 更多