Score:0

Docker - linux container run on Windows has different time

af flag

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 ?

Score:2
ar flag

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.

Irbis avatar
af flag
You could be right, because command ```cat /etc/timezone``` returns: No such file or directory
cn flag
`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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.