【问题标题】:`docker build` hangs based on order of install`docker build` 根据安装顺序挂起
【发布时间】:2021-07-30 18:34:57
【问题描述】:

鉴于此Dockerfile

FROM ubuntu:20.04

RUN set -ex && apt-get update

RUN set -ex && \
    apt-get install -y \
    git

RUN set -ex && \
    apt-get install -y \
    cmake

ENV HOME_DIR /home/develop

WORKDIR ${HOME_DIR}

docker build 挂起配置tzdata

$ DOCKER_BUILDKIT=0 docker build -f Docker/Dockerfile -t cmake:latest .
Sending build context to Docker daemon  161.8kB
Step 1/6 : FROM ubuntu:20.04
 ---> 7e0aa2d69a15
Step 2/6 : RUN set -ex && apt-get update
 ---> Using cache
 ---> 78e8a28063b0
Step 3/6 : RUN set -ex &&     apt-get install -y    git
 ---> Using cache
 ---> d400fc509ae8
Step 4/6 : RUN set -ex &&     apt-get install -y    cmake
 ---> Running in 2c58632e70a3
+ apt-get install -y cmake
Reading package lists...
Building dependency tree...
Reading state information...
...
Setting up tzdata (2021a-0ubuntu0.20.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: 

如果我颠倒gitcmake 的顺序,它将成功构建。为什么顺序很重要?

我在 MacOS 11 (Big Sur) 上运行 Docker 20.10.5。

【问题讨论】:

    标签: git docker ubuntu cmake


    【解决方案1】:

    通过设置 DEBIAN_FRONTEND 变量来抑制来自 apt 的提示,这可以通过仅在构建期间存在的构建 arg 来完成(允许交互式用户执行到容器中):

    FROM ubuntu:20.04
    
    ARG DEBIAN_FRONTEND=noninteractive
    RUN set -ex && \
        apt-get update && \
        apt-get install -y \
        git
    
    RUN set -ex && \
        apt-get update && \
        apt-get install -y \
        cmake
    
    ENV HOME_DIR /home/develop
    
    WORKDIR ${HOME_DIR}
    

    另外,请注意更新应与安装步骤一起运行,以避免陈旧的缓存破坏构建。

    【讨论】:

      【解决方案2】:

      CMake 包必须在安装之前静默选择tzdata 的默认选择(作为 git 的依赖项?)。奇怪,但解决方法很简单。在Dockerfile 顶部附近添加以下行:

      ENV TZ=America/Los_Angeles
      RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime
      RUN echo "$TZ" > /etc/timezone
      
      RUN apt-get update
      RUN apt-get install -y tzdata
      

      当然,将America/Los_Angeles 替换为您认为最适合您的应用程序的时区,可能是UTC

      【讨论】:

        【解决方案3】:

        Git 将 perl 作为其依赖项之一安装,并且还安装了 Term::ReadLine perl 模块。有了这个模块,安装cmake时,debconf可以初始化Readline前端,可以等待输入。但是如果你先安装cmake,这个模块在本地还不存在,debconf设置tzdata失败,会使用默认配置。

        以上有日志证明,如果我们先安装cmake:

        Setting up tzdata (2021a-0ubuntu0.20.04) ...
        [243/1270]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: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
        debconf: falling back to frontend: Teletype
        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:
        Use of uninitialized value $_[1] in join or string at /usr/share/perl5/Debconf/DbDriver/Stack.pm line 111.
        Current default time zone: '/UTC'
        Local time is now:      Sat May  8 21:19:41 UTC 2021.
        Universal Time is now:  Sat May  8 21:19:41 UTC 2021.
        Run 'dpkg-reconfigure tzdata' if you wish to change it.
        

        【讨论】:

          【解决方案4】:

          在我的MacOS Catalina version 10.15.7Docker version 19.03.13, build 4484c46d9d

          我在我的Dockerfile 中添加了这个,它可以很好地工作而不会挂起

          RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get -y install tzdata

          【讨论】:

            猜你喜欢
            • 2020-07-17
            • 1970-01-01
            • 1970-01-01
            • 2019-02-08
            • 2023-01-11
            • 2013-05-28
            • 2014-07-21
            • 2016-02-28
            • 2015-09-10
            相关资源
            最近更新 更多