一、问题情况如下:容器日志显示时间,差了8个小时
错误时间
正确时间
二、解决方法:
1.解决docker容器与宿主机时间不一致问题:在启动容器时,把系统时间挂载到容器内,添加如下参数 -v etc/localtime:/etc/localtime:ro ro表示只读
2.解决docker 容器与tomcat 应用打印日志时间不一致问题:在tomcat/bin/catalina.sh文件中修改tomcat JAVA_OPTS,添加如下内容
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Duser.timezone=GMT+08
复制
将配置文件,加载至容器
- './config/catalina.sh:/usr/local/tomcat/bin/catalina.sh'
复制
执行命令:重新加载卷
登录容器查看日志信息:
docker exec -it 2cbce5974658 /bin/bash # 登录容器
root@2cbce5974658:/usr/local/tomcat# date
Wed Aug 21 15:35:38 CST 2019
root@2cbce5974658:/usr/local/tomcat# tail -f logs/catalina.2019-08-21.log
Aug 21, 2019 3:35:19 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Aug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager <init>
INFO: ProcessManager implementation is LinuxProcessManager
Aug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.OfficeProcess prepareInstanceProfileDir
WARNING: profile dir '/usr/local/tomcat/temp/.jodconverter_socket_host-127.0.0.1_port-8100' already exists; deleting
Aug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.OfficeProcess start
INFO: starting process with acceptString 'socket,host=127.0.0.1,port=8100,tcpNoDelay=1' and profileDir '/usr/local/tomcat/temp/.jodconverter_socket_host-127.0.0.1_port-8100'
Aug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.OfficeProcess start
INFO: started process; pid = 81
tail: unrecognized file system type 0x794c7630 for ‘logs/catalina.2019-08-21.log’. please report this to bug-coreutils@gnu.org. reverting to polling
复制
总结:
1.docker容器和系统时间不一致是因为docker容器的原生时区为0时区,而国内系统为东八区
2.容器中运行的tomcat应用打出的日志时间和通过date -R方式获取的容器标准时间有八个小时时间差。也就是容器时间和系统时间一致,但是部署的应用和容器时间不一致。
爱运维^_^爱分享
文章转载自Linux运维技术之路,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
轻松上手:使用 Docker Compose 部署 TiDB 的简易指南
shunwahⓂ️
87次阅读
2025-04-27 16:19:49
Dify使用deepseek
golang算法架构leetcode技术php
53次阅读
2025-04-21 10:35:08
GreatSQL社区月报 | 2025.3
GreatSQL社区
31次阅读
2025-04-15 09:49:59
Harbor使用指南
老柴杂货铺
28次阅读
2025-04-12 00:03:42
Qwen3震撼发布,用openGauss x Dify抢先体验,秒速搭建智能知识库
Gauss松鼠会
18次阅读
2025-05-07 10:05:56
Qwen3震撼发布,用openGauss x Dify抢先体验,秒速搭建智能知识库
openGauss
13次阅读
2025-05-06 10:19:35
5.1 | MySQL 企业版的 Docker 安装方式
严少安
10次阅读
2025-05-12 00:14:16
Docker的极简入门知识整理
济南小老虎
8次阅读
2025-04-20 22:08:26
CentOS 9 (stream) 安装 Docker
韩公子的Linux大集市
8次阅读
2025-04-21 07:08:32
安利一个墙内镜像站
济南小老虎
7次阅读
2025-04-24 06:37:49