【问题标题】:In Dockerfile how to answer option [duplicate]在Dockerfile中如何回答选项[重复]
【发布时间】:2022-02-22 19:45:01
【问题描述】:

我需要从 Dockerfile 创建一个 docker 映像。我的 Dockerfile 示例如下。

FROM ubuntu:20.04
......
..........
..............
RUN apt install -y aptitude

RUN sh -c '/bin/echo -e "n\ny\ny" | aptitude -f install python-dev'

错误:

Do you want to continue? [Y/n/?] Abort.
The command '/bin/sh -c sh -c '/bin/echo -e "n\ny\ny" | aptitude -f install python-dev'' returned a non-zero code: 1

通过 dockerfile,即使我在下面尝试过。但还是没有成功。

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update && DEBIAN_FRONTEND=noninteractive aptitude -f install python-dev

错误:

Do you want to continue? [Y/n/?] n (stdin unavailable)
Abort.
The command '/bin/sh -c apt update && DEBIAN_FRONTEND=noninteractive aptitude -f install python-dev' returned a non-zero code: 1

我的应用程序代码编译有各种依赖项,在 docker 容器中手动我可以使用 aptitude -f install python-dev 包进行安装,没有任何问题。在安装过程中,我需要回答如下安装问题。

aptitude -f install python-dev

no
yes
yes

请给我通过dockerfile回答yes and No问题的解决方案。提前致谢。

【问题讨论】:

  • 是要避开提示,还是要回答?
  • 我想通过在我的 dockerfile 中找到答案来安装包。
  • (对于这些安装,我建议坚持使用apt-get;正如@Paolo 的回答和其他一些人建议的那样,使用apt-get install -y 选项。不要使用更高级别的工具,例如apt或 Dockerfile 中的 aptitude。)

标签: docker dockerfile


【解决方案1】:

您可以使用-y 选项以静默方式接受安装程序提示:

RUN sh -c '/bin/echo -e "n\ny\ny" | aptitude -y -f install python-dev'

来自aptitude --help

-y              Assume that the answer to simple yes/no questions is 'yes'.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 2018-10-19
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多