Automatically Setting Timezone on Dockerfile

As I lives in Indonesia, I would prefer to use GMT+7 as my selected timezone. It will make my log easier to check and also easier to find events at a certain time.

Below are a sample command to set timezone on Ubuntu based docker images :

#################################################################
# Dockerfile for Excellent Ubuntu Standard
# Based on Ubuntu 18.04
# Created by Masim Vavai Sugianto
#################################################################
FROM ubuntu:18.04
MAINTAINER Masim Vavai Sugianto <mynickname@vavai.net>
ARG DEBIAN_FRONTEND=noninteractive
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && apt-get update && apt-get install apt-utils tzdata
RUN echo "tzdata tzdata/Areas select Asia\ntzdata tzdata/Zones/Asia select Jakarta" > /tmp/tz ; debconf-set-selections /tmp/tz; rm /etc/localtime /etc/timezone; dpkg-reconfigure -f noninteractive tzdata

Leave a Reply

Your email address will not be published. Required fields are marked *