Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to synchronize the time of docker Container

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Today's Xiaobian shares with you the problem of how to synchronize docker container time. Sometimes after the docker container is created, you may find that the container time is inconsistent with the host time, which requires synchronizing their times.

For example, the host uses CST time zone, CST refers to (China Shanghai Time); the container uses UTC time zone, UTC refers to (Coordinated Universal Time). There are several ways to unify the two time zones:

1) localtime of shared host

Specify startup parameters when creating the container, mount the localtime file into the container, and ensure that the time zone used by the two is the same.

# docker run -ti -d --name my-nginx -v /etc/localtime:/etc/localtime:ro docker.io/nginx /bin/bash

2)localtime of replication host

[root@slave-1 ~]# docker cp /etc/localtime 87986863838b:/etc/

Then log in to the container, check the time, and find that it has synchronized with the host time.

[root@slave-1 ~]# docker exec -ti 87986863838b /bin/bashroot@87986863838b:/# dateFri May 12 11:26:19 CST 2019

3) When creating dockerfile file, customize the time format and time zone of the mirror. Add the following to the dockerfile file:

...... FROM tomcatENV CATALINA_HOME /usr/local/tomcat.......# RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone...

After saving, you can use docker build command to generate an image.

Container cloud products are implemented by deploying Kubernetes Engine on cluster servers through docker technology. Powerful, simple and easy to use, with tens of thousands of linux images, seconds to open, lightweight container cloud product link https://www.yisu.com/cloud/

As a senior professional cloud computing service provider and cloud security service provider in the industry, it is committed to providing cloud host rental services such as "Cloud Virtual Machine, Bare Metal Server, High Defense Server, Hong Kong Server and American Server" as well as comprehensive solutions for enterprises on the cloud for the majority of Internet enterprise users and enterprise users in traditional industries. It has the characteristics and advantages of "security and stability, simplicity and use, high service availability and high cost performance." It is specially customized for enterprises on the cloud. It can meet the rich and diversified application scenarios of users.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report