docker 设置时区的方法

1. 在Dockerfile中设置镜像时区

# 设定时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

2. 创建容器时设置时区

将宿主机与容器的时间进行挂载

-v /etc/localtime:/etc/localtime

3. 进入容器进行设置

进入容器

docker exec -it 容器名 /bin/bash

设置时区

rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

转载:https://blog.enianteam.com/u/sun/content/194

posted @ 2023-05-20 22:39  lqqgis  阅读(184)  评论(0编辑  收藏  举报