How to set timezone inside alpine base docker image?

Viewed 11581
2 Answers

You need to install the tzdata package and then set the enviroment variable TZ to a timezone. (List with all the timezones)

FROM alpine:latest
RUN apk add --no-cache tzdata
ENV TZ=Europe/Copenhagen

Output

$ docker run --rm alpine date
Tue Aug 31 09:52:08 UTC 2021

$ docker run --rm myimage date
Tue Aug 31 11:52:13 CEST 2021

This is my Dockerfile and it's work:

FROM alpine:latest

# Essentials
RUN apk add -U tzdata
ENV TZ=America/Santiago
RUN cp /usr/share/zoneinfo/America/Santiago /etc/localtime

you have to replace 'America/Santiago' to your timezone'

Related