I have the following line in the Dockerfile.
RUN apt-get install -y tzdata
When I run it, it asks for my input. After I provided my input, it hung there. Does anybody know how to solve this problem?
Step 25/25 : RUN apt-get install -y tzdata
---> Running in ee47a1beff84
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 189 kB of archives.
After this operation, 3104 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 tzdata all 2018i-0ubuntu0.18.04 [189 kB]
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: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Fetched 189 kB in 1s (219 kB/s)
Selecting previously unselected package tzdata.
(Reading database ... 25194 files and directories currently installed.)
Preparing to unpack .../tzdata_2018i-0ubuntu0.18.04_all.deb ...
Unpacking tzdata (2018i-0ubuntu0.18.04) ...
Setting up tzdata (2018i-0ubuntu0.18.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:
``
One line only:
You can use
ARG
andENV
directives to your advantage:This way
DEBIAN_FRONTEND
will be defined only while you build your image whileTZ
will persist at runtime.You need to execute serie of commands:
(commands which start with
#
are comments and you can ignore them)The best way is to create script, copy the script to container and execute it In Dockerfile:
Set two environment variables in a docker-compose file. One disables the prompt, and the other sets the timezone.
docker-compose.yml
Then simply install
tzdata
in your image.Dockerfile
To test:
Make sure if you're using @petertc's solution and are doing
apt-get update && apt-get install
on the same line that theDEBIAN_FRONTEND
statement is after the&&
:Right:
Wrong:
From a simple Dockerfile it works but it might require further tweaking (tz is 19:25 but 16:25 inside docker, idc now because it is for automation purpose on a ARM64 jetson nano)
For me, it worked and I preferred this way (this way you don't need to set a noninteractive mode):
Set an environment variable with your timezone, for instance:
ENV TZ=Europe/Madrid
Then, print this variable into a file and then link that file to the file which the the configuration process will read when installing tzdata:
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Finally, install tzdata normally:
RUN apt-get update && apt-get install -y tzdata
Extracted from: https://dev.to/setevoy/docker-configure-tzdata-and-timezone-during-build-20bk
On focal 20.04 the solutions using
TZ=...
andDEBIAN_FRONTEND=...
does not work anymore. It used to work till bionic 18.04. The docker file snippet that works for focal look like:The solution is mostly derived from another stackoverflow topic.
On ubuntu22:04 image, I got:
so that the Dockerfile would not build.
Taken from Getting tons of debconf messages unless TERM is set to linux #58, I needed to run:
which stopped debconf reporting on the missing terminal and also stopped the tzdata installer from opening the locations menu during the Dockerfile build.