1、查看容器中的时区
[root@localhost jenkins]# docker exec -it jenkins cat /etc/timezone
Etc/UTC而本地使用的是Asia/shanghai
[root@localhost jenkins]# timedatectl | grep 'Time zone'Time zone: n/a (CST, +0800)###查看
[root@localhost jenkins]# cd /usr/share/zoneinfo/Asia/
[root@localhost Asia]# ll2、使用root 登陆容器中,修改时区
root@localhost:/# echo "Asia/Shanghai" > /etc/timezone
root@localhost:/# exit
exit3、将本地时间拷贝
[root@localhost Asia]# docker cp /usr/share/zoneinfo/Asia/Shanghai jenkins:/etc/localtime
Successfully copied 1.54kB to jenkins:/usr/share/zoneinfo/Etc/UTC4、重启Jenkins服务
[root@localhost Asia]# docker restart jenkins5、验证
[root@localhost Asia]# docker exec -it -u root jenkins date
Thu Nov 16 13:41:43 CST 2023