web-dev-qa-db-fra.com

Comment installer tzdata sur une image Docker Ubuntu?

J'ai la ligne suivante dans le Dockerfile.

RUN apt-get install -y tzdata

Lorsque je l'exécute, il demande mon avis. Après avoir fourni ma contribution, elle s'est accrochée là. Est-ce que quelqu'un sait comment résoudre ce problème?

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:
``
13
user1424739

Vous devez exécuter une série de commandes:

# set noninteractive installation
export DEBIAN_FRONTEND=noninteractive
#install tzdata package
apt-get install -y tzdata
# set your timezone
ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
dpkg-reconfigure --frontend noninteractive tzdata

(commandes commençant par # sont des commentaires et vous pouvez les ignorer)

La meilleure façon est de créer un script, de le copier dans un conteneur et de l'exécuter dans Dockerfile:

ADD yourscript.sh /yourscript.sh
RUN /yourscript.sh
14
Romeo Ninov

Définissez deux variables d'environnement dans un fichier docker-compose. L'un désactive l'invite et l'autre définit le fuseau horaire.

docker-compose.yml

version: '3.7'
services:
  timezone:
    build: .
    environment:
      - TZ=America/New_York
      - DEBIAN_FRONTEND=noninteractive

Ensuite, installez simplement tzdata dans votre image.

Dockerfile

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y tzdata
# Testing command: Print the date.  It will be in the timezone set from the compose file.
CMD date

Tester:

docker-compose up
4
Steven Spungin

Une seule ligne:

RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata
3
okwap