Docker Ubuntu18.04でtzdataをinstallするときにtimezoneの選択をしないでinstallする

docker imageのベースイメージをubuntu18.04に上げた時に
`tzdata` を `apt-get install` するところで止まってしまってハマったのでメモしておく

# 素のubuntu17.10の場合

```dockerfile

FROM ubuntu:17.10

RUN apt-get update \
  && apt-get install -y tzdata
```

```
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu:17.10
 ---> e4422b8da209
Step 2/2 : RUN apt-get update   && apt-get install -y tzdata
 ---> Running in dbe30f24e997
Get:1 http://security.ubuntu.com/ubuntu artful-security InRelease [83.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu artful InRelease [237 kB]
Get:3 http://security.ubuntu.com/ubuntu artful-security/universe Sources [20.5 kB]
Get:4 http://security.ubuntu.com/ubuntu artful-security/multiverse amd64 Packages [1822 B]
Get:5 http://security.ubuntu.com/ubuntu artful-security/restricted amd64 Packages [2931 B]
Get:6 http://security.ubuntu.com/ubuntu artful-security/universe amd64 Packages [77.7 kB]
Get:7 http://security.ubuntu.com/ubuntu artful-security/main amd64 Packages [219 kB]
Get:8 http://archive.ubuntu.com/ubuntu artful-updates InRelease [88.7 kB]
Get:9 http://archive.ubuntu.com/ubuntu artful-backports InRelease [74.6 kB]
Get:10 http://archive.ubuntu.com/ubuntu artful/universe Sources [11.1 MB]
Get:11 http://archive.ubuntu.com/ubuntu artful/universe amd64 Packages [10.8 MB]
Get:12 http://archive.ubuntu.com/ubuntu artful/main amd64 Packages [1416 kB]
Get:13 http://archive.ubuntu.com/ubuntu artful/multiverse amd64 Packages [185 kB]
Get:14 http://archive.ubuntu.com/ubuntu artful/restricted amd64 Packages [14.7 kB]
Get:15 http://archive.ubuntu.com/ubuntu artful-updates/universe Sources [42.2 kB]
Get:16 http://archive.ubuntu.com/ubuntu artful-updates/universe amd64 Packages [139 kB]
Get:17 http://archive.ubuntu.com/ubuntu artful-updates/main amd64 Packages [345 kB]
Get:18 http://archive.ubuntu.com/ubuntu artful-updates/multiverse amd64 Packages [4380 B]
Get:19 http://archive.ubuntu.com/ubuntu artful-updates/restricted amd64 Packages [2931 B]
Get:20 http://archive.ubuntu.com/ubuntu artful-backports/universe amd64 Packages [4359 B]
Get:21 http://archive.ubuntu.com/ubuntu artful-backports/main amd64 Packages [1462 B]
Fetched 24.8 MB in 10s (2465 kB/s)
Reading package lists...
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 205 kB of archives.
After this operation, 3085 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu artful-updates/main amd64 tzdata all 2017c-0ubuntu0.17.10 [205 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 205 kB in 1s (126 kB/s)
Selecting previously unselected package tzdata.
(Reading database ... 4111 files and directories currently installed.)
Preparing to unpack .../tzdata_2017c-0ubuntu0.17.10_all.deb ...
Unpacking tzdata (2017c-0ubuntu0.17.10) ...
Setting up tzdata (2017c-0ubuntu0.17.10) ...
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.26.0 /usr/local/share/perl/5.26.0 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /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

Current default time zone: 'Etc/UTC'
Local time is now:      Tue May 22 13:32:20 UTC 2018.
Universal Time is now:  Tue May 22 13:32:20 UTC 2018.
Run 'dpkg-reconfigure tzdata' if you wish to change it.

Removing intermediate container dbe30f24e997
 ---> 33d07aec2e72
Successfully built 33d07aec2e72
```

ちょっと長いけど、`default time zone` が `Etc/UTC` でnoninteractiveにinstallされる

# 素のubuntu18.04の場合

```dockerfile

FROM ubuntu:18.04

RUN apt-get update \
  && apt-get install -y tzdata
```

実はこれも素の状態だとそのままinstallされる

# 特定のpackageが入ったubuntu18.04の場合

```
…
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:
```

↑ここで止まる

- timezoneの選択で止まってしまう
- ベースイメージを18.04変えたらtimezoneの選択で止まるようになった
	- 17.10の時はdefaultでinstallされていた
- 素の18.04にtzdataをinstallする場合は止まらない

この状況から推測するに…
`素の18.04に何か特定のpackageを追加すると止まるようになるのではないか`

元々、ベースイメージに色々追加でパッケージを入れていたので、**1個ずつ確認した**ところ…
`git`が原因だった

```dockerfile

FROM ubuntu:18.04

RUN apt-get update \
  && apt-get install -y \
    git

RUN apt-get update \
  && apt-get install -y tzdata
```

# 解決策
```
ENV DEBIAN_FRONTEND=noninteractive
```

を入れて `noninteractive` に installする

```dockerfile

FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
  && apt-get install -y \
    git

RUN apt-get update \
  && apt-get install -y tzdata
```