The time in the docker container is inconsistent with the system time in linux (alpine image)

The time in the docker container is inconsistent with the system time in linux (nginx:alpine image)

1. Background environment

  • linux7.9
  • Basic linux7.9 uses docker to pull the container of nginx:alpine image

2. Phenomenon

  • linux system time

image-20230307201751391

  • container time

image-20230307201816047

3. Solutions

The time zone in centos is a soft link

image-20230307200410249

But in the alpine mirror container, there is no such file under etc

So specify the time zone file in the container

1、添加工具
apk update && apk add tzdata

2、创建时区文件
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone

3、检查
date

Guess you like

Origin blog.csdn.net/m0_49562857/article/details/129390777