如何避免在 Docker 构建过程中出现问题?

问题描述 投票:0回答:3

我正在构建一个基于 Ubuntu 18.04 的 Docker 镜像。 它构建正常,但在完成之前我在 Powershell 控制台中收到:

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:
----

据我了解,它等待我的一些答复,但我无法输入任何数字,即键盘上没有反应。如何避免这个问题呢?可能是我可以在 dockerfile 中添加 CMD 吗?

docker ubuntu dockerfile
3个回答
42
投票

我在

Dockerfile
中遇到了同样的问题,然后我使用了
ARG DEBIAN_FRONTEND=noninteractive
在基本图像之后,它对我有用:

示例 Dockerfile:

FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive

18
投票

这对我有用。

ENV TZ=Asia/Kolkata \
    DEBIAN_FRONTEND=noninteractive

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

0
投票

避免在 Docker 中使用

apt
,而是使用
apt-get
。 DEBIAN_FRONTEND=noninteractive 在
apt
上不起作用。

此外,还可以推荐一些需要此类输入的软件包。因此,在您的

--no-install-recommends
运行中添加
apt-get install -y
选项。例如

RUN export DEBIAN_FRONTEND=noninteractive && \
    # To avoid the installation of non essential packages
    apt-get install -yq --no-install-recommends \
    wget git

使用 tzdata,我设置了以下环境变量以使其正常工作:

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Africa/Johannesburg 
© www.soinside.com 2019 - 2024. All rights reserved.