如何自动回答安装提示(除了“是”以外)?

6

简介

我正在尝试构建一个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

更新

我在这里找到了一些相关的东西(链接),建议使用DEBIAN_FRONTEND=noninteractive运行apt install。这解决了我的问题。 :) 但是,我仍然想知道如何响应提示,因为那里提供的解决方案只提供了如何抑制它们。

2个回答

3

非常好。谢谢!你能提供一个在这种情况下使用expect的例子吗? - Ashton Wiersdorf
不好意思,我忘了大部分的 expect。已经使用它超过二十年了。一般来说,您不应该需要使用它。 - Basile Starynkevitch

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接