Skip to content

Instantly share code, notes, and snippets.

@sidja
Created January 23, 2017 02:11
Show Gist options
  • Save sidja/833eb9824ada2684773553824f28e910 to your computer and use it in GitHub Desktop.
Save sidja/833eb9824ada2684773553824f28e910 to your computer and use it in GitHub Desktop.
How to change time zone in docker container ubuntu
FROM ubuntu:16.04
ENV TZ=Australia/Melbourne
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN dpkg-reconfigure --frontend noninteractive tzdata
@peter279k
Copy link

peter279k commented Dec 28, 2019

When running this Dockerfile during Docker building image on Ubuntu 18.04 or Ubuntu 16.04, it will present following error message:

Step 4/4 : RUN dpkg-reconfigure --frontend noninteractive tzdata
 ---> Running in 9e7c2c0130f2
dpkg-query: package 'tzdata' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
/usr/sbin/dpkg-reconfigure: tzdata is not installed

It seems that the tzdata is not installed on Ubuntu 18.04 or Ubuntu 16.04.

To fix this problem, the Dockerfile should change into following snippets:

# For Ubuntu 16.04, change into: FROM ubuntu:16.04
FROM ubuntu:18.04

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install tzdata

ENV TZ=Asia/Taipei
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN dpkg-reconfigure --frontend noninteractive tzdata

@MitchTalmadge
Copy link

MitchTalmadge commented Dec 19, 2020

Thank you for this, sidja and peter. Really helpful.

@cfloress
Copy link

thanks!!!!

@skywallger
Copy link

Very Good. Complete with this solution.

Copy link

ghost commented May 31, 2022

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment