Skip to content

Instantly share code, notes, and snippets.

@peter279k
Forked from sidja/Dockerfile
Created January 3, 2020 05:54
Show Gist options
  • Save peter279k/610b0b45abfd716b655d8b740ed878e7 to your computer and use it in GitHub Desktop.
Save peter279k/610b0b45abfd716b655d8b740ed878e7 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
Author

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

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