Setting Timezone in Docker Container
Quote from moshe on 19/11/2020, 10:35 amProblem
Docker Container does not obey to timezone settings and use default UTC
Solution
Depends on your linux distribution you need to add TZ utils to the operating system and run the following commands
Alpine Linux / NodeJS ( based on alpine linux
USER root
RUN apk update && apk upgrade && apk add ca-certificates && \
update-ca-certificates && apk add –update tzdata && \
rm -rf /var/cache/apk/*Ubuntu Image
USER root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y tzdata && \
apt-get clean && \
rm -fr /etc/localtimeCentOS Image
USER ROOT
cd etc
mv /etc/localtime /etc/localtime.backup
ln -s /usr/share/zoneinfo/US/Central localtime
Problem
Docker Container does not obey to timezone settings and use default UTC
Solution
Depends on your linux distribution you need to add TZ utils to the operating system and run the following commands
Alpine Linux / NodeJS ( based on alpine linux
USER root
RUN apk update && apk upgrade && apk add ca-certificates && \
update-ca-certificates && apk add –update tzdata && \
rm -rf /var/cache/apk/*
Ubuntu Image
USER root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y tzdata && \
apt-get clean && \
rm -fr /etc/localtime
CentOS Image
USER ROOT
cd etc
mv /etc/localtime /etc/localtime.backup
ln -s /usr/share/zoneinfo/US/Central localtime
Quote from moshe on 19/11/2020, 10:36 amCheck Timezone settings in NodeJS container
TZ=America/Los_Angeles
nodeWelcome to Node.js v12.18.2.
Type “.help” for more information.process.env.TZ
Check Timezone settings in NodeJS container
TZ=America/Los_Angeles
node
Welcome to Node.js v12.18.2.
Type “.help” for more information.
process.env.TZ