天天看点

docker容器内时区更改

docker内时间和系统时间差8小时

d6612fcb89aa为我的docker容器id

[[email protected] ~]# docker exec d6612fcb89aa date  ---查看docker容器时间
Mon Aug 30 06:55:10 UTC 2021

[[email protected] ~]# docker exec -it d6612fcb89aa sh -c 'ln -s  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime'  ---创建软链接
ln: failed to create symbolic link '/etc/localtime': File exists
[[email protected] ~]# docker exec -ti -u root gerrit sh   ----以root进入gerrit容器
sh-4.4# rm localtime  ----删除文件
sh-4.4#exit

[[email protected] ~]# docker exec -it d6612fcb89aa sh -c 'ln -s  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime'
ln: failed to create symbolic link '/etc/localtime': Permission denied  ---权限不够被禁止

[[email protected] ~]# docker exec -it -u root d6612fcb89aa sh -c 'ln -s  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime'   ----以root身份操作

[[email protected] ~]# docker exec -it d6612fcb89aa sh -c 'date'
Mon Aug 30 15:06:42 CST 2021  ----更改成功

           

参考资料:https://zhuanlan.zhihu.com/p/104198177

https://blog.csdn.net/HYZX_9987/article/details/119149982