apt-get install tzdata noninteractive

This is the script I used

(Updated Version with input from @elquimista from the comments)

#!/bin/bash
export DEBIAN_FRONTEND=noninteractive

ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
apt-get install -y tzdata
dpkg-reconfigure --frontend noninteractive tzdata

Seems to work fine.

As one liner:

DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata

I have recently found the following solution in a Dockerfile building the Cingulata FHE library:

ln -snf /usr/share/zoneinfo/$(curl https://ipapi.co/timezone) /etc/localtime

It basically uses the API provided by ipapi.co to retrieve the timezone information. This automatically configures the timezone properly instead of skipping the dialog and using the default (UTC).


To avoid playing directly with symlinks and to run configuration only once, I suggest to use debconf-set-selections command:

echo 'tzdata tzdata/Areas select Europe' | debconf-set-selections
echo 'tzdata tzdata/Zones/Europe select Paris' | debconf-set-selections
DEBIAN_FRONTEND="noninteractive" apt install -y tzdata

If someone wants to achieve it in Dockerfile, use as below.

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y install tzdata