Forum Navigation
You need to log in to create posts and topics.

Setting Timezone in Docker Container

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

 

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