Post

Synology NAS- Docker container time zone settings

As everyone knows, in the Dockerfile, which is the specification for building a Docker image, you can add the apt package installation required for the image. This causes the apt package to be installed in the Docker image while building it.

When you first attempt to install the apt package in a typical Ubuntu system, you are interactively asked for the region and city to set the time zone in the tzdata settings. However, this results in Docker image build failure because the Docker image build process does not support interactive procedures.

DEBIAN_FRONTEND environment variable

So, to solve this problem, you can omit asking for the region and city to set the time zone while building the Docker image by setting the DEBIAN_FRONTEND environment variable to noninteractive in the Dockerfile.

Below is a simple example of a Dockerfile.

1
2
3
4
5
6
7
8
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y vim git wget rsyslog sudo

# add and so on ..

CMD bash

There are no problems up to this point. However, the problem starts when you develop software that utilizes the current time and use an API to get the current time within the source code. The time of a system without a time zone setting is based on UTC. Therefore, there is a possibility that the time-related functions of the software development language you use and system time processing overlap, causing software malfunction.

tzdata and time zone settings

So, although it is very annoying, after creating and attaching a container, you must manually set the time zone separately using the command below. Of course, you can set the container’s time zone on a Linux system outside of a Docker container, but since I use Synology NAS’s Docker, it was difficult to find a way to do so.

1
dpkg-reconfigure tzdata

Below is my example for setting the time zone. If the time in the text below is your local time, the time zone is set correctly.

  • Local time is now
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
root@img:~# dpkg-reconfigure tzdata
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------
  
Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the
time zones in which they are located.
  
1. Africa   3. Antarctica  5. Arctic Ocean  7. Atlantic Ocean  9. Indian Ocean    11. System V timezones  13. None of the above
2. America  4. Australia   6. Asia          8. Europe          10. Pacific Ocean  12. US
Geographic area: 6
  
Please select the city or region corresponding to your time zone.
  
1. Aden      11. Baku        21. Damascus          31. Hong Kong  41. Kashgar       51. Makassar      61. Pyongyang
2. Singapore      81. Ujung Pandang
...
9. Baghdad   19. Chongqing   29. Hebron            39. Kamchatka  49. Macau         59. Phnom Penh    69. Seoul
10. Tokyo          89. Yekaterinburg
...
Time zone: 69
  
Current default time zone: 'Asia/Seoul'
Local time is now:      Thu Feb  1 23:46:23 KST 2024.
Universal Time is now:  Thu Feb  1 14:46:23 UTC 2024.

This post is licensed under CC BY 4.0 by the author.