AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 949991
Accepted
user1424739
user1424739
Asked: 2019-01-21 17:50:55 +0800 CST2019-01-21 17:50:55 +0800 CST 2019-01-21 17:50:55 +0800 CST

如何在 ubuntu docker 镜像上安装 tzdata?

  • 772

我在 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:
``
docker
  • 9 9 个回答
  • 146149 Views

9 个回答

  • Voted
  1. Best Answer
    petertc
    2019-11-20T05:11:05+08:002019-11-20T05:11:05+08:00

    仅一行:

    RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
    
    • 180
  2. SnakE
    2020-05-14T06:21:55+08:002020-05-14T06:21:55+08:00

    您可以使用ARG和ENV指令对您有利:

    ARG DEBIAN_FRONTEND=noninteractive
    ENV TZ=Europe/Moscow
    RUN apt-get install -y tzdata
    

    这种方式DEBIAN_FRONTEND只会在您构建图像时定义,而TZ将在运行时持续存在。

    • 95
  3. Romeo Ninov
    2019-01-21T19:28:22+08:002019-01-21T19:28:22+08:00

    您需要执行一系列命令:

        # set noninteractive installation
        export DEBIAN_FRONTEND=noninteractive
        # install tzdata package
        apt-get install -y tzdata
        # set your timezone
        ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
        dpkg-reconfigure --frontend noninteractive tzdata
    

    (以注释开头的命令#可以忽略)

    最好的方法是创建脚本,将脚本复制到容器并在 Dockerfile 中执行:

    ADD yourscript.sh /yourscript.sh
    RUN /yourscript.sh
    
    • 51
  4. Steven Spungin
    2019-07-13T15:44:56+08:002019-07-13T15:44:56+08:00

    在 docker-compose 文件中设置两个环境变量。一个禁用提示,另一个设置时区。

    码头工人-compose.yml

    version: '3.7'
    services:
      timezone:
        build: .
        environment:
          - TZ=America/New_York
          - DEBIAN_FRONTEND=noninteractive
    

    然后只需安装tzdata在您的映像中。

    Dockerfile

    FROM ubuntu:18.04
    RUN apt-get update && apt-get install -y tzdata
    # Testing command: Print the date.  It will be in the timezone set from the compose file.
    CMD date
    

    去测试:

    docker-compose build timezone
    
    • 16
  5. Ben J
    2020-10-14T08:58:45+08:002020-10-14T08:58:45+08:00

    确保您使用的是@petertc 的解决方案并且在语句位于apt-get update && apt-get install以下的同一行上执行:DEBIAN_FRONTEND&&

    正确的:

    RUN apt-get update && DEBIAN_FRONTEND="noninteractive" TZ="America/New_York" apt-get install -y tzdata
    

    错误的:

    RUN DEBIAN_FRONTEND="noninteractive" TZ="America/New_York" apt-get update && apt-get install -y tzdata
    
    • 13
  6. Alsushi
    2020-04-23T09:53:50+08:002020-04-23T09:53:50+08:00

    从一个简单的 Dockerfile 它可以工作,但可能需要进一步调整(tz 是 19:25,但 docker 内部是 16:25,现在是 idc,因为它是用于 ARM64 jetson nano 上的自动化目的)

    RUN export TZ=Europe/Paris
    RUN pip3 install -U Cython contextlib2 pillow lxml jupyter matplotlib
    RUN DEBIAN_FRONTEND=noninteractive apt-get install protobuf-compiler python-pil python-lxml python-tk -y
    
    Unpacking protobuf-compiler (3.0.0-9.1ubuntu1) ...
    Setting up python-chardet (3.0.4-1) ...
    Setting up tzdata (2019c-0ubuntu0.18.04) ...
    
    Current default time zone: 'Etc/UTC'
    Local time is now:      Wed Apr 22 16:25:17 UTC 2020.
    Universal Time is now:  Wed Apr 22 16:25:17 UTC 2020.
    Run 'dpkg-reconfigure tzdata' if you wish to change it.
    
    Setting up libxss1:arm64 (1:1.2.2-1) ...
    
    • 2
  7. Akronix
    2021-01-13T03:01:53+08:002021-01-13T03:01:53+08:00

    对我来说,它起作用了,我更喜欢这种方式(这样你就不需要设置非交互模式):

    使用您的时区设置环境变量,例如: 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

    • 2
  8. minghua
    2020-12-03T10:33:14+08:002020-12-03T10:33:14+08:00

    在焦点 20.04 上,使用TZ=...和DEBIAN_FRONTEND=...不再起作用的解决方案。它曾经工作到仿生 18.04。适用于焦点的 docker 文件片段如下所示:

       ## preesed tzdata, update package index, upgrade packages and install needed software
       RUN truncate -s0 /tmp/preseed.cfg && \
           (echo "tzdata tzdata/Areas select America" >> /tmp/preseed.cfg) && \
           (echo "tzdata tzdata/Zones/America select Los_Angeles" >> /tmp/preseed.cfg) && \
           debconf-set-selections /tmp/preseed.cfg && \
           rm -f /etc/timezone /etc/localtime && \
           apt-get update && \
           DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
           apt-get install -y tzdata
       ## cleanup of files from setup
       RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    

    该解决方案主要来自另一个stackoverflow主题。

    • 1
  9. questionto42standswithUkraine
    2021-12-24T15:11:09+08:002021-12-24T15:11:09+08:00

    在 ubuntu22:04 图片上,我得到:

    Setting up locales (2.34-0ubuntu3) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    Generating locales (this might take a while)...
      de_AT.UTF-8... done
      ...
      sv_SE.UTF-8... done
    Generation complete.
    Setting up libjansson4:amd64 (2.13.1-1.1build2) ...
    Setting up libsasl2-modules-db:amd64 (2.1.27+dfsg2-2build1) ...
    Setting up tzdata (2021e-1ubuntu1) ...
    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   3. Antarctica  5. Arctic  7. Atlantic  9. Indian    11. US
      2. America  4. Australia   6. Asia    8. Europe    10. Pacific  12. Etc
    Geographic area:
    

    这样 Dockerfile 就不会构建。

    取自获取大量 debconf 消息,除非 TERM 设置为 linux #58,我需要运行:

    RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
    # And afterwards whatever you like, for example:
    RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get -y \
    --no-install-recommends install ...
    

    它停止了 debconf 报告丢失的终端,并且还阻止了 tzdata 安装程序在 Dockerfile 构建期间打开位置菜单。

    • 1

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve