`docker build` hängt basierend auf der Installationsreihenfolge

Lesezeit: 4 Minuten

Benutzer-Avatar
Stefan Rasku

Angesichts dessen 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}

Das docker build hängt die Konfiguration 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: 

Wenn ich die Reihenfolge umkehre git und cmake es wird erfolgreich gebaut. Warum sollte die Reihenfolge wichtig sein?

Ich verwende Docker 20.10.5 auf MacOS 11 (Big Sur).

Unterdrücken Sie die Eingabeaufforderung von apt, indem Sie die Variable DEBIAN_FRONTEND setzen, was mit einem Build-Argument erfolgen kann, das nur während des Builds existiert (was interaktiven Benutzern erlaubt, in einen Container ausgeführt zu werden):

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}

Beachten Sie auch, dass das Update mit dem Installationsschritt ausgeführt werden sollte, um zu vermeiden, dass veraltete Caches Builds beschädigen.

Das CMake-Paket muss automatisch eine Standardauswahl für auswählen tzdata bevor es installiert wird (als Abhängigkeit von Git?). Seltsam, aber die Problemumgehung ist einfach genug. Fügen Sie die folgenden Zeilen am oberen Rand Ihrer hinzu 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

Natürlich ersetzen America/Los_Angeles mit der Zeitzone, die Ihrer Meinung nach für Ihre Anwendung am besten geeignet ist UTC.

Git installiert Perl als eine seiner Abhängigkeiten, und das installiert die Term::ReadLine Perl-Modul auch. Mit diesem Modul kann debconf bei der Installation von cmake die Readline Frontend und kann auf Eingaben warten. Aber wenn Sie cmake zuerst installieren, existiert dieses Modul lokal noch nicht, und Debconf wird tzdata nicht einrichten und wird die Standardkonfiguration verwenden.

Das Obige wird durch die Protokolle bewiesen, wenn wir zuerst cmake installieren:

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.

Auf meinem MacOS Catalina version 10.15.7 und Docker version 19.03.13, build 4484c46d9d

Ich habe dies in meiner hinzugefügt Dockerfile und es funktioniert gut ohne hängen

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

1014640cookie-check`docker build` hängt basierend auf der Installationsreihenfolge

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy