`docker build` 根据安装顺序挂起

Ste*_*sku 7 git ubuntu cmake docker

鉴于这种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}
Run Code Online (Sandbox Code Playgroud)

挂起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: 
Run Code Online (Sandbox Code Playgroud)

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

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

BMi*_*tch 10

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

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}
Run Code Online (Sandbox Code Playgroud)

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