【问题标题】:How do I answer install prompts (other than with "yes") automatically?如何自动回答安装提示(“是”除外)?
【发布时间】:2018-08-31 04:05:02
【问题描述】:

概要

我正在尝试构建 Docker 映像,但它失败了,因为我尝试使用 apt install 获取的软件包之一在安装过程中提示用户。我想回复这个提示,但我不知道如何以非交互方式进行。

说明

我正在构建一个 Docker 映像,我的 Dockerfile 有以下行:

RUN apt install -y texlive-latex-extra

(这个包有一些我需要的 LaTeX 库。)

在安装过程中,这会停止:

Setting up tzdata (2018d-1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

  1. Africa        6. Asia            11. System V timezones
  2. America       7. Atlantic Ocean  12. US
  3. Antarctica    8. Europe          13. None of the above
  4. Australia     9. Indian Ocean
  5. Arctic Ocean  10. Pacific Ocean
Geographic area:

此时,它正在等待一些输入。 (在此之后还有一个选择时区的提示——我认为这对于 LaTeX 文件中的 \today 指令很重要。¯\_(ツ)_/¯)

如何以非交互方式回答这个问题?

到目前为止我已经尝试过什么

我试过这样做:

apt install -y texlive-latex-extra <(echo 12 && echo 2)

还有这个:

echo 12 && echo 2 | apt install -y texlive-latex-extra

第一个死于此错误:

apt install -y texlive-latex-extra <(echo 12 && echo 9)

第二个好像没有效果。

作为参考,到目前为止,这是我的 Dockerfile:

FROM ubuntu:latest

RUN apt update && apt upgrade -y && apt install -y curl bzip2 tar make gcc wget gnupg unzip
RUN apt install -y texlive
RUN apt install -y nodejs npm git
RUN npm install -g bower
RUN apt install -y texlive-latex-extra

更新

我发现了一些接近 here 的内容,它建议将 apt installDEBIAN_FRONTEND=noninteractive 一起运行。这充分解决了我的问题。 :) 但是,我仍然想知道如何响应提示,因为那里提供的解决方案只提供了如何抑制它们。

【问题讨论】:

    标签: dockerfile apt tex-live


    【解决方案1】:

    如果您想编写终端交互脚本,您可以在 Linux 上使用 expect(这可能不太容易;您需要预测交互)。

    记住terminal emulators 是复杂而神秘的东西(因为terminalsVT100 一样复杂)。请参阅termios(3)pty(7) 并阅读The Tty demystified

    【讨论】:

    • 固体。谢谢!你能提供一个在这种情况下使用expect 的例子吗?
    • 没有。我忘记了大部分的期望。二十多年前用过。一般来说,您不需要使用它。
    猜你喜欢
    • 2012-12-13
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    相关资源
    最近更新 更多