Docker Build Stuck on tzdata Timezone Prompt

DOCKER GUIDE

Docker Build Stuck on tzdata Timezone Prompt

Fix Debian/Ubuntu image builds that stop for interactive timezone configuration and understand exactly when the docker build command needs an argument.

The symptom

A package installation pulls in tzdata and the build waits for a geographic area/timezone. Docker builds should not depend on a person answering a debconf prompt.

Case 1 — You only need the build to be non-interactive

FROM ubuntu:24.04

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata && \
    rm -rf /var/lib/apt/lists/*

DEBIAN_FRONTEND=noninteractive applies to that package-install command. It tells Debian's debconf system not to open an interactive frontend; it does not magically make every program non-interactive.

Matching build command:

docker build -t my-image .

No build argument is required because the Dockerfile does not expect one.

Case 2 — The image should use one fixed timezone

FROM ubuntu:24.04

ENV TZ=Etc/UTC
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone && \
    rm -rf /var/lib/apt/lists/*

Matching build command:

docker build -t my-image .

Again, no argument is required: the timezone is defined in the Dockerfile. UTC is a sensible default for many server workloads; choose a local timezone only when the application genuinely requires it.

Case 3 — Make the timezone configurable at build time

FROM ubuntu:24.04

ARG TZ=Etc/UTC
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive TZ="$TZ" apt-get install -y --no-install-recommends tzdata && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone && \
    rm -rf /var/lib/apt/lists/*

Because ARG TZ=Etc/UTC has a default, the normal build still works:

docker build -t my-image .

Override it only when needed:

docker build --build-arg TZ=Asia/Kolkata -t my-image .

The important relationship is Dockerfile declares ARG TZ → --build-arg TZ=... can supply/override it. Passing a build argument should not be presented as required when the Dockerfile already supplies a default.

Why not persist DEBIAN_FRONTEND with ENV?

DEBIAN_FRONTEND controls package configuration behavior. Persisting ENV DEBIAN_FRONTEND=noninteractive can affect later package operations inside containers created from the image. Scope it to the installation step instead.

Verify

docker build --no-cache -t tz-test .
docker run --rm tz-test date

The build should finish without waiting for input. If you configured a timezone, verify date reflects the intended runtime configuration.

Decision table

Dockerfile choiceBuild command
No configurable TZdocker build -t my-image .
ENV TZ=Etc/UTCdocker build -t my-image .
ARG TZ=Etc/UTC, use defaultdocker build -t my-image .
ARG TZ=Etc/UTC, overridedocker build --build-arg TZ=Asia/Kolkata -t my-image .