Troubleshooting Docker container time zone and timing issues

Source: Internet
Author: User
Tags add time

Today, during system integration testing, a test bug was submitted by the tester because the time to commit the business data was biased against the actual time (Beijing time), resulting in a statistical anomaly. Since our integration test is to provide testers with a complete Docker image as a test environment, the reason should be on the container time setting.

After you get the delivered Docker image, you start to enter the container console and use the date command to see that the time is incorrect. Check that the host time is correct, so it must be that the container started without synchronizing the time zone with the host, because the test image is built directly by dockfile, so the problem is basically Dingzhun on the Dockerfile file. When the Dockerfile check is turned on, it is found that the sync settings with the host time zone are indeed missing. So how to add the time zone synchronization process to record, at the same time for students who have encountered similar problems for reference: The following Alpine made of Docker image as an example (also our test image): 1 Dockerfile Revision 1.1 Add Install Tzdata package installs the Tzdata installation package when the package is installed, and cannot clean up the installation package after the build is successful
#定义环境变量ENV  Time_zone asiz/shanghai#dockerfile add command run \
#安装tzdata安装包 && apk add--no-cache tzdata \ 1.2 Add time zone configuration after you install this installation package, each time zone configuration information is generated in the/usr/share/zoneinfo directory. Alpine Directory does not have timezone and locatime configuration, we need to overwrite the time zone value to the timezone and localtime configuration of Alpine, the command is as follows:
" RUN ... #安装tzdata安装包&& apk add--no-cache tzdata \  #设置时区 echo"$ {Time_zone} " >/etc/ln -sf/usr/share/zoneinfo/${time_zone}/etc/localtime \
At this point, Dockerfile's modification has been completed. 2 host time zone and time check if the host time and time are correct, use the following command:
"[[email protected]~]# timedatectl Local Time: Tue .- A- -  +: the: -EST Universal Time: Wed .- A- -  Geneva: the: -UTC RTC Time: Wed .- A- -  Geneva: the: -Time Zone:america/new_york (EST,-0500)//default to West zone fiveNTP enabled:n/ANTP SYNCHRONIZED:NORTCinchlocal tz:no DST Active:nolast DST Change:dst ended at Sun .- One- .  on: -: -EDT Sun .- One- .  on:xx:xxEstnext DST CHANGE:DST begins (the clock jumps one hour forward) at Sun .-Geneva- A  on: -: -EST Sun .-Geneva- A Geneva:xx:xxedt# modified to East eight [[email protected]~]# Timedatectl Set-timezone asia/Shanghai Local Time: Wed .- A- - Ten: -:TenCST Universal Time: Wed .- A- -  Geneva: -:TenUTC RTC Time: Wed .- A- -  Geneva: -:TenTime Zone:asia/shanghai (CST, +0800) NTP enabled:n/ANTP SYNCHRONIZED:NORTCinchlocal Tz:no DST active:n/A[[email protected]~]#DateWed Dec - Ten: -: theCst .#调整时间 [[email protected]~]#Date-S"2016-12-13 21:54:20"#时间同步, no execution is not effective [[email protected]~]# Clock-W[[Email protected]~]# timedatectl Local Time: Tue .- A- -  A: -: -CST Universal Time: Tue .- A- -  -: -: -UTC RTC Time: Tue .- A- -  -: -: -Time Zone:asia/shanghai (CST, +0800) NTP enabled:n/ANTP SYNCHRONIZED:NORTCinchlocal Tz:no DST active:n/a " '
The host time zone and times have been adjusted. 3. Build the container test regenerate the image based on the above Dockerfile and use the Run command to start the container to view the window time
Date: £ º
Synchronized with the host, the entire adjustment process is complete ~ ~

Troubleshooting Docker container time zone and timing issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.