Will the container auto-configure time docker with the host machine?

Giving I have already correctly changed the time zone of the docker container. Do I need to install an NTP server inside the docker container to periodically synchronize time or will the container synchronize time with its host machine?

+83
timezone time docker clock ntp
Apr 02 '14 at 2:51 on
source share
4 answers

If you are on OSX running boot2docker see this issue: https://github.com/boot2docker/boot2docker/issues/290

Time synchronization becomes a problem because the boot2docker host has its time drift while your OS is sleeping. Time synchronization with the docker container cannot be resolved by starting your container with -v /etc/localtime:/etc/localtime:ro

Instead, this time you need to run this periodically on OSX:

 /usr/local/bin/boot2docker ssh sudo ntpclient -s -h pool.ntp.org 

Update for Kitematic Users

If you are using Kitematic , which is now the proposed mechanism for launching and launching Docker on OSX, you will have to run this command periodically:

 docker-machine ssh default 'sudo ntpclient -s -h pool.ntp.org' 

Or, for older versions of dockers

 docker-machine ssh dev 'sudo ntpclient -s -h pool.ntp.org' 

Update for users of the new native Docker for OSX

New beta version of Docker removes VirtualBox and Docker Machine. The latest docker builds (currently 1.12.1-beta25 (build: 11807)) seem to have the ability to detect when there was a time gap, and adjust accordingly. So this should no longer be a problem ... hooray !!

+97
Oct 19 '14 at 18:44
source share

The simplest solution is to run your container with the -v /etc/localtime:/etc/localtime:ro option. In this way:

 #run without tz info: docker run --rm -t -i ubuntu date Wed Apr 2 18:40:07 UTC 2014 # run with tz info: docker run --rm -t -i -v /etc/localtime:/etc/localtime:ro ubuntu date Wed Apr 2 11:40:29 PDT 2014 
+38
Apr 02 '14 at 18:42 on
source share

https://github.com/sameersbn/docker-gitlab/issues/77

See the answer of sameersbn.

 option 1: -v /etc/localtime:/etc/localtime:ro option 2: -e "TZ=Asia/Shanghai" 
+38
Aug 05 '14 at 2:25
source share

In Docker for Mac OS X Beta, I experienced significant drift in a virtual machine based on Alpine Linux. From the Alpine Linux FAQ you can synchronize your VM clock with the following command.

 ntpd -d -q -n -p pool.ntp.org 

However, accessing the terminal in a virtual machine is another issue that can be done if you use the screen command.

 screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty 

This path is a symbolic link that points to /dev/ttys003 on my system.

Once you log in, note that moby login just root without a password. After you are done, CTRL-A, D will disconnect from the screen session.

NOTE. This was documented by Docker for Mac Trouble Shooting , but it seems to have been filmed. I was fortunate enough to show it while it is at Dockercon 2016. It seems that Docker is trying to completely distract the VM from the experience, which explains why this is no longer documented.

+21
Jun 30 '16 at 21:53 on
source share



All Articles