0

I work on Windows 10. I use a docker image based on Ubuntu 18.04 (FROM ubuntu:18.04). When I run a Linux container using Docker the time returned by "date" command differs from the time on the Windows host machine. The time in the Linux container is two hours earlier than in the Windows host machine. Based on the research I have tried -v option with docker run command but it doesn't work (I run Docker commands from the powershell terminal or Windows cmd scripts, Docker Desktop by default uses Linux containers):

docker run -it --rm -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro myimage bash

I'm looking for an "offline" solution. How to fix that ?

Irbis
  • 101
  • 1

1 Answers1

2

You probably need to install the package tzdata in the container. This contains the information about the time zones. /etc/timezone tells what TZ to use, but not what that TZ looks like.

The reason this is not included is that in many cases it's not relevant to know local time inside an container. Only UTC time is relevant, and not tzdata is needed for that.

vidarlo
  • 6,654
  • 2
  • 18
  • 31
  • You could be right, because command ```cat /etc/timezone``` returns: No such file or directory – Irbis Jul 27 '23 at 11:06
  • 1
    `in many cases it's not relevant to know local time inside an container`. I believe that to be accurate for about 99.999% of cases, particularly in data center or cloud environments where UTC is common. Then there are the run everything in a container on your desktop community and need a procedure for changing the time in Linux containers due to they don't sync with host by default. – Greg Askew Jul 27 '23 at 11:31