简体   繁体   中英

Windows Docker Desktop Linux mode - docker container time skew

Question: How can I map docker container time to my local PC time to sync the time inside the docker container?

From my windows 10 PC, I am running Linux mode docker desktop version 2.2.0.4 (43472), docker Engine 19.03.8.

All the docker containers created are showing massive time skew from that of the host:

From centos 8 docker container:

[root@ /]# date Thu May 7 01:18:16 UTC 2020

From docker host running Window Doker desktop on Windows 10 PC:

PS> date

14 May 2020 14:42:17

I tried to create a new container with -v option as below:

docker container run -it -v c:\docker_volumes\docker1:/storage -v /etc/localtime:/etc/localtime:ro --name centos7-squid centos:7.7.1908 /bin/bash

I get the error below

Unable to find image 'centos:7.7.1908' locally 7.7.1908: Pulling from library/centos f34b00c7da20: Pull complete Digest: sha256:50752af5182c6cd5518e3e91d48f7ff0cba93d5d760a67ac140e2d63c4dd9efc Status: Downloaded newer image for centos:7.7.1908 C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\"/etc/localtime\\" to rootfs \\"/var/lib/docker/overlay2/c7e86cffdc46c354f19b25fa97146ce8f2caee653793219719b043c97040d1b7/merged\\" at \\"/var/lib/docker/overlay2/c7e86cffdc46c354f19b25fa97146ce8f2caee653793219719b043c97040d1b7/merged/usr/share/zoneinfo/UTC\\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

I fixed it by setting the hardware clock of the virtual machine running docker:

docker run --rm --privileged alpine hwclock -s

credit: https://blog.jverkamp.com/2017/11/15/clock-drift-in-docker-containers/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM