我在 Dockerfile 中有以下行。
RUN apt-get install -y tzdata
当我运行它时,它会询问我的输入。在我提供我的输入后,它就挂在那里了。有谁知道如何解决这个问题?
Step 25/25 : RUN apt-get install -y tzdata
---> Running in ee47a1beff84
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
tzdata
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 189 kB of archives.
After this operation, 3104 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 tzdata all 2018i-0ubuntu0.18.04 [189 kB]
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Fetched 189 kB in 1s (219 kB/s)
Selecting previously unselected package tzdata.
(Reading database ... 25194 files and directories currently installed.)
Preparing to unpack .../tzdata_2018i-0ubuntu0.18.04_all.deb ...
Unpacking tzdata (2018i-0ubuntu0.18.04) ...
Setting up tzdata (2018i-0ubuntu0.18.04) ...
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 4. Australia 7. Atlantic 10. Pacific 13. Etc
2. America 5. Arctic 8. Europe 11. SystemV
3. Antarctica 6. Asia 9. Indian 12. US
Geographic area:
``
仅一行:
您可以使用
ARG
和ENV
指令对您有利:这种方式
DEBIAN_FRONTEND
只会在您构建图像时定义,而TZ
将在运行时持续存在。您需要执行一系列命令:
(以注释开头的命令
#
可以忽略)最好的方法是创建脚本,将脚本复制到容器并在 Dockerfile 中执行:
在 docker-compose 文件中设置两个环境变量。一个禁用提示,另一个设置时区。
码头工人-compose.yml
然后只需安装
tzdata
在您的映像中。Dockerfile
去测试:
确保您使用的是@petertc 的解决方案并且在语句位于
apt-get update && apt-get install
以下的同一行上执行:DEBIAN_FRONTEND
&&
正确的:
错误的:
从一个简单的 Dockerfile 它可以工作,但可能需要进一步调整(tz 是 19:25,但 docker 内部是 16:25,现在是 idc,因为它是用于 ARM64 jetson nano 上的自动化目的)
对我来说,它起作用了,我更喜欢这种方式(这样你就不需要设置非交互模式):
使用您的时区设置环境变量,例如:
ENV TZ=Europe/Madrid
然后,将此变量打印到一个文件中,然后将该文件链接到配置过程在安装 tzdata 时将读取的文件:
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
最后,正常安装tzdata:
RUN apt-get update && apt-get install -y tzdata
摘自:https ://dev.to/setevoy/docker-configure-tzdata-and-timezone-during-build-20bk
在焦点 20.04 上,使用
TZ=...
和DEBIAN_FRONTEND=...
不再起作用的解决方案。它曾经工作到仿生 18.04。适用于焦点的 docker 文件片段如下所示:该解决方案主要来自另一个stackoverflow主题。
在 ubuntu22:04 图片上,我得到:
这样 Dockerfile 就不会构建。
取自获取大量 debconf 消息,除非 TERM 设置为 linux #58,我需要运行:
它停止了 debconf 报告丢失的终端,并且还阻止了 tzdata 安装程序在 Dockerfile 构建期间打开位置菜单。