How to change Timezone on Docker with Ubuntu 16.04

Ubuntu 16.04 and every other use UTC by default.

I want to change to JST. So I search about this on the web, and some site said to use like this.

Show list of time zone

$ timedatectl list-timezones

But I executed this command, and then above message occurs.

Error about bus happen

$ timedatectl list-timezones
Failed to create bus connection: No such file or directory

It is a problem to use systemd. Ubuntu has used systemd since 16.04.

To use systemd on docker container is pretty tough. So I used tzdata. It is still available to install via apt on Ubuntu 16.04, but if you can also change time zone with systemd. See this document.

I write this config in Dockerfile like this. And build the container.


FROM ubuntu:16.04

  apt-get -y install tzdata && \
  ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

Then I enter the container and check time zone.

root@4dbd2aff2747:~# cat /etc/timezone

root@9dce4012502e:~# strings /etc/localtime

The docker container’s time zone becomes JST!

2 thoughts on “How to change Timezone on Docker with Ubuntu 16.04”

Leave a Reply

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