如何为“RUN”命令的交互式命令填写用户输入?

35

我只是在 Docker 镜像上尝试 ubuntu:19.04,希望在镜像中安装 tcl,因此我执行了以下命令:

RUN apt update && apt install tcl

然后它将给出一些交互式命令:

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   3. Antarctica  5. Arctic  7. Atlantic  9. Indian    11. SystemV  13. Etc
2. America  4. Australia   6. Asia    8. Europe    10. Pacific  12. US

我这里有两个问题:

(1) 如果在 Dockerfile 中写了以下命令,输入一个数字后,“docker build .” 似乎会因此挂起。

(2) 我希望不必手动输入选项,是否有办法在“RUN”中提供一个选项,以便自动执行?

2个回答

57

你试过禁用它吗?

FROM ubuntu:19.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt update && apt install -y tcl

这句话的意思是,我的 docker/build_docker.sh 脚本出现了问题,第三行和第五行分别提示 ENVRUN 命令未找到。 - Dmitriy Ogureckiy
2
不应使用 ENV 来设置该值。请使用 ARG 或内联设置:DEBIAN_FRONTEND=noninteractive apt install -y ...。参见 此问题 - Logan

23

这对我很有效。

ENV TZ=Asia/Kolkata \
    DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install tzdata

你能解释一下你是怎么到这里来的吗?特别是TZ和tzdata是如何工作的。 - Krunal
1
不要使用 ENV 设置 DEBIAN_FRONTEND。参见此问题 - Logan

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