docker logs 容器名查看的日志总比宿主机的日志相差8小时,感觉是因为时区不对的原因
version: "3"
services:
sh-user-center:
container_name: sh-user-center
restart: always
image: 192.168.1.154/test/sh-user-center:v1
network_mode: host
volumes:
- /data/logs/paas/application/:/data/logs/paas/application/
- /data/logs/paas/audit/:/data/logs/paas/audit/
- /data/logs/paas/point/:/data/logs/paas/point/
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime #将时间文件映射到容器中
[root@localhost java]# docker exec -it sh-user-center /bin/bash
root@localhost:/# date
Sat Apr 10 16:15:45 CST 2021
发现容器内系统时间是正确的,但是日志时间还是错误的
FROM java:8
COPY *.jar /app.jar
COPY test.sh /test.sh
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo ‘Asia/Shanghai’ >/etc/timezone #最后发现是在dockerfile中需要将文件拷贝进去
EXPOSE 8000
CMD /test.sh
这样就保证了docker容器时间和宿主机时间一致了