N
N
Nikolay Baranenko2020-10-29 20:42:41
linux
Nikolay Baranenko, 2020-10-29 20:42:41

How to make timestamp on localhost match timestamp in docker?

On localhost and in docker, the time differs by 3 hours, in docker it lags behind

[email protected]:/# cat /etc/timezone 
Europe/Moscow
[email protected]:/# exit
exit
[email protected]:~$ cat /etc/timezone 
Europe/Moscow


Time zones match

Dockerfile

ENV TZ=Europe/Moscow
RUN apt-get install -y tzdata
RUN cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


How to make timestamp on localhost match timestamp in docker?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2020-10-29
@drno-reg

umvr
Dockerfile

FROM ubuntu
ENV TZ=Europe/Moscow
RUN apt-get update && apt-get install -yy tzdata
RUN cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

Assembly and launch
$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM ubuntu
 ---> d70eaf7277ea
Step 2/4 : ENV TZ=Europe/Moscow
 ---> Using cache
 ---> 24c7e693dacf
Step 3/4 : RUN apt-get update && apt-get install -yy tzdata
 ---> Using cache
 ---> 8d1bbd58900b
Step 4/4 : RUN cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
 ---> Using cache
 ---> b65965107725
Successfully built b65965107725
$ docker run b65965107725 date
Thu Oct 29 21:09:13 MSK 2020
$ date
Thu Oct 29 21:09:15 MSK 2020

Z
zohan1993, 2020-10-29
@zohan1993

you can, for example, forward from the host

docker run  \
...
-v /etc/timezone:/etc/timezone:ro \
-v /etc/localtime:/etc/localtime:ro \
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question