The difference between the docker container time and the local time is 8 hours, the docker container time is inconsistent, and the container time is not synchronized [notes]

background

Many systems are virtualized on the same physical machine, the system version is OpenEuler 22.03, and the service is started/rancher deployed through docker, and it is found that the time inconsistency still occurs in the following situations:

  1. TZ=Asia/Shanghai is specified in the dockerfile build script
  2. Rancher deployment, environment deployment parameter TZ=Asia/Shanghai
  3. The startup parameter mounts /etc/localtime:/etc/localtime

Solution

Map the time zone information of the physical machine, the following is selected according to the deployment service method

  • docker start command parameter passing
docker run -d -p xxx:xx -v /usr/share/zoneinfo:/usr/share/zoneinfo 镜像名:版本

Example:

docker run -d -p 8080:8080 -v /usr/share/zoneinfo:/usr/share/zoneinfo app:1.0
  • rancher start mapping
  • insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/qq_41070393/article/details/129199904