【问题标题】:Running shell script while building docker image在构建 docker 映像时运行 shell 脚本
【发布时间】:2019-04-09 14:08:12
【问题描述】:

我有一个带有 install.sh 脚本的自定义包,我想在构建 docker 映像时运行它(意思是 - 将 ./install.sh 放入 Dockerfile 中)。我本可以将它与容器一起运行,但我想要一个包含所需包的图像(在install 脚本中提到)。

我尝试了什么:

  1. RUN /bin/sh/ -c "./install.sh"
  2. RUN ./install.sh

说错了 -

/bin/sh install.sh not found

或

/bin/sh ./install.sh not found

这可能是一个重复的问题,但我在任何地方都没有找到答案。任何帮助将不胜感激。

【问题讨论】:

  • 为什么不在你的 Dockerfile 中创建./install.sh,然后再执行它?
  • 请分享可以重现您的问题的最小 dockerfile。

标签: shell docker dockerfile docker-build


【解决方案1】:

您必须在 dockerfile 中使用以下命令将 install.sh 复制到 docker 映像中:

COPY install.sh /tmp

然后使用您的RUN 命令运行它:

RUN /bin/sh -c "/tmp/install.sh"

或

RUN sh /tmp/install.sh

在运行之前不要忘记使install.sh 可执行:

chmod +x /tmp/install.sh

【讨论】:

  • 使install.sh 可执行:chmod +x install.sh
  • 我假设 'tmp' 是我从中复制 install.sh @MSaadat 的文件夹
  • 不起作用。我仍然收到此错误 - /bin/sh: 1: ./install.sh: not found The command '/bin/sh -c /bin/sh -c "./install.sh"' returned a non-zero code: 127 @MSaadat
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-14
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 2020-10-06
  • 1970-01-01
相关资源
最近更新 更多