角色 | 地域 | 配置 | 操作系统 | Kubernetes 版本信息 |
节点 | 华南地区 (广州) | CPU:1核,内存::1GB,带宽:1 Mbps 系统盘:50GB(普通云硬盘) | CentOS Linux 7(Core) | 1.16.3 |
date
docker run -it centos /bin/sh
date
exit
vim Dockerfile.txt
FROM centosRUN rm -f /etc/localtime \\&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \\&& echo "Asia/Shanghai" > /etc/timezone
docker build -t centos7-test:v1 -f Dockerfile.txt .
date
docker run -it centos7-test:v1 /bin/sh
date
exit
/etc/localtime
:需确保该主机时区配置文件存在且时区正确。/usr/share/zoneinfo/Asia/Shanghai
:当本地 /etc/localtime
不存在或者时区不正确时,可选择直接挂载该配置文件。/etc/localtime
:/etc/localtime
到容器内。date
docker run -it -v /etc/localtime:/etc/localtime centos /bin/sh
date
exit
/usr/share/zoneinfo/Asia/Shanghai
:/usr/share/zoneinfo/Asia/Shanghai
到容器内。date
docker run -it -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime centos /bin/sh
date
exit
mountPath:/etc/localtime
为例,介绍在 YAML 文件中如何通过数据卷挂载主机时区配置到容器内,解决容器内时区不一致的问题。vim pod.yaml
apiVersion: v1kind: Podmetadata:name: testnamespace: defaultspec:restartPolicy: OnFailurecontainers:- name: nginximage: nginx-testimagePullPolicy: IfNotPresentvolumeMounts:- name: date-configmountPath: /etc/localtimecommand: ["sleep", "60000"]volumes:- name: date-confighostPath:path: /etc/localtime
kubectl create -f pod.yaml
date
kubectl exec -it test date
本页内容是否解决了您的问题?