Docker timezone on Ubuntu 16.04 Image

I created a Docker conatainer using an ubuntu 16.04 image.

docker run -it -d --name contain the name -v / var / www / public --privileged ubuntu

after creating the container i check the date in the container

#date

Tue Oct 25 08:10:34 UTC 2016

But I need to set up Asia / Calcutta , so I'm trying to change

/ etc. / time zone

Then stop the file and start the Docker container. It does not work. Show Show the same time.

Suggest me how to change the time zone in the docker container After creating the container?

+5
source share
7 answers

Updating /etc/timezone is the usual way, but there is an error in Xenial , which means that it does not work.

Instead, you need to create a link from the required time zone to etc/localtime :

 FROM ubuntu:xenial RUN ln -fs /usr/share/zoneinfo/US/Pacific-New /etc/localtime && dpkg-reconfigure -f noninteractive tzdata 
+17
source

Try:

 echo "Asia/Kolkata" > /etc/timezone rm /etc/localtime dpkg-reconfigure -f noninteractive tzdata 

You must do rm /etc/localtime due to a Ubuntu error.

+5
source

In ubuntu 16.04, I was missing tzdata, so I had to install it. Working solution was

  ENV TZ 'Europe/Tallinn' RUN echo $TZ > /etc/timezone && \ apt-get update && apt-get install -y tzdata && \ rm /etc/localtime && \ ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ dpkg-reconfigure -f noninteractive tzdata && \ apt-get clean 
+4
source

SOLVED:

 FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y software-properties-common apt-utils locales tzdata RUN echo "tzdata tzdata/Areas select Europe" > timezone.txt RUN echo "tzdata tzdata/Zones/Europe select Rome" >> timezone.txt RUN debconf-set-selections timezone.txt RUN rm /etc/timezone RUN rm /etc/localtime RUN dpkg-reconfigure -f noninteractive tzdata 
0
source

As said here , the secret is that dpkg-reconfigure tzdata simply creates /etc/localtime as a copy, hardlink or symlink (preferred symbolic link) to a file in /usr/share/zoneinfo . Thus, this can be done completely from your Docker file. Consider:

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

And as a bonus, TZ will also be correctly installed in the container.

It is also an agnostic distribution, so it works with almost all Linux.

0
source

If you use docker-compose, just add one line to your docker-compose.yml .

version: '3'

 services: ubuntu-local: image: ubuntu:16.04 restart: on-failure command: python3 run_my_code.py working_dir: /code volumes: - ./code:/code - /etc/localtime:/etc/localtime:ro # <--add this line to set timezone environment: - PYTHONUNBUFFERED=1 
0
source

I used this approach:

  • Copy the file / etc / localtime somewhere.

  • Open it and find this number (highlighted in yellow) enter image description here

  • -3 corresponds to Moscow time. For Berlin, -1 is set. If you need a positive value, set UTC2

  • Copy and modify / etc / timezone to suit your time zone.

  • Link them to the container

Result:

enter image description here

0
source

Source: https://habr.com/ru/post/1258741/


All Articles