所有分类
  • 所有分类
  • 未分类

Docker Compose-解决容器时间不正确的问题

简介

本文介绍Docker Compose如何解决容器时区不正确导致时间不正确的问题。

方案1:添加environment参数

修改docker-compose.yml文件添加environment参数:

environment:
  - TZ=Asia/Shanghai

完整文件如下:

version: '3'
services:
     nginx:
      image: 'nginx:latest'
      restart: always
      container_name: nginx
      ports:
        - 80:80
        - 8081:8081
        - 443:443
      environment:
        TZ : Asia/Shanghai
      volumes:
        - /app/nginx/conf.d:/etc/nginx/conf.d
        - /app/nginx/logs:/etc/nginx/logs
      command:  nginx -g 'daemon off;'

方案2:绑定时间文件

修改docker-compose.yml文件绑定事件参数:

volumes:
  - /etc/timezone:/etc/timezone
  - /etc/localtime:/etc/localtime

完整文件

version: '3'
services:
     nginx:
      image: nginx:latest
      restart: always
      container_name: nginx
      ports:
        - 80:80
        - 8081:8081
        - 443:443
      environment:
        TZ : Asia/Shanghai
      volumes:
        - /app/nginx/conf.d:/etc/nginx/conf.d
        - /app/nginx/logs:/etc/nginx/logs
        - /etc/timezone:/etc/timezone
        - /etc/localtime:/etc/localtime
      command:  nginx -g 'daemon off;'
0

评论0

请先

显示验证码
没有账号?注册  忘记密码?

社交账号快速登录