Dockerfile RUN apt install Geographic Area/Time zoneでビルドが止まる時の対処法

qemu-user-binfmtなどタイムゾーンの入力を要求するライブラリをRUN apt installでインストールする場合、そのGeographic Areaの入力でビルドが止まりDockerイメージをビルドできません。 その回避方法です。 (apt install なのでdebianベースのイメージビルドの場合です。)

現象

以下のようなライブラリをインストールしようとすると、

RUN apt install -y qemu-user-binfmt

このようにGeographic area入力要求でビルドが止まってしまいます。 半角数字を入力しても先に進みません。

$ docker build --no-cache -t MyImage Dockerfile .
[+] Building 808.0s (5/10)              docker:default
 => [internal] load .dockerignore       0.0s
                :
                :
 => transferring context: 401B          0.0s
 => [2/6] RUN dpkg --add-architecture i386 &&  apt -y update && apt install -y make --fix-missing &&  apt insta  807.9s
 => => # 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:
_

解決策

  1. ENV DEBIAN_FRONTEND=noninteractive』を設定する。(例の2行目)
    • 入力要求しない設定を環境変数に設定する。
    • このnoninteractiveが設定されるとデフォルト値が採用されます。
  2. echo Asia/Tokyo > /etc/timezone』を設定(例の4行目)
    • /etc/timezoneファイルには元々Etc/UTCが入っていました。
    • Asia/Tokyoを書込んでおかないと、UTC(Universal Time Coordinated:協定世界時間、日本時間より9時間遅い世界基準時刻)が採用されてしまうと思います。
例: Dockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN dpkg --add-architecture i386 && \
 echo Asia/Tokyo > /etc/timezone && \
 echo export PS1="'\[\e[01;32m\]\u@\h \[\e[0m\]:\[\e[01;36m\]\w\[\e[0m\] \$ '" >> ~/.bashrc && \
 apt -y update && apt install -y make --fix-missing && \
                :
                :
 apt install -y -q qemu-user-binfmt

イメージをビルドして、コンテナを実行して、コンテナ内のコマンドプロンプトに入って確認して見ます。

$ docker build --no-cache -t MyImage Dockerfile .  //イメージをビルド

$ docker run --name MyContainer -itd --rm MyImage  //イメージを使ってコンテナ起動

$ docker exec -it MyContainer /bin/bash    //<---これでコンテナに入ります

ちゃんとインストールされていますね。

root@d1335f64eb0a :/ # apt list |grep qemu-user-binfmt

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

qemu-user-binfmt/focal-security,now 1:4.2-3ubuntu6.27 amd64 [installed]

おしまい

コメント

タイトルとURLをコピーしました