Docker container synchronized with system time

After the Docker container is created, you will find that the container time is inconsistent with the host time, as follows:

[root@localhost ~]# date
Fri Apr 22 12:24:01 CST 2022

bash-5.1# date
Fri Apr 22 04:24:11 UTC 2022

It is necessary to synchronize their time so that the container time is consistent with the host time.
Methods as below:

Copy the host file to the container
docker cp /usr/share/zoneinfo/Asia/Shanghai container ID or container name: /usr/share/zoneinfo/Asia

Enter the container and execute the following command:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Check the confirmation time in the container:
bash-5.1# date -R
Fri Apr 22 15:45:19 CST 2022
[root@localhost ~]# date
2022 April 22 Friday 15:45:24 CST

Guess you like

Origin blog.csdn.net/weixin_48773672/article/details/124344419