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

原文网址:Docker Compose--解决容器时间不正确的问题_IT利刃出鞘的博客-CSDN博客

简介

本文介绍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;'
相关推荐
山上三树2 小时前
进程状态详解
linux·运维·服务器
山上三树2 小时前
task_struct 详解
运维·服务器·网络
oMcLin2 小时前
如何打造Linux运维监控平台:Prometheus + Grafana实战与性能优化
linux·运维·prometheus
木卫二号Coding3 小时前
jupyterlab-安装与启动
linux·运维·服务器
fengyehongWorld3 小时前
Linux logger命令
linux·运维·服务器
一只鹿鹿鹿3 小时前
网络信息与数据安全建设方案
大数据·运维·开发语言·网络·mysql
好好学习啊天天向上3 小时前
最新:ubuntu上源码安装llvm,还没有成功
linux·运维·ubuntu
小宇的天下4 小时前
Calibre nmDRC 运行机制与规则文件(13-2)
运维·开发语言
Guistar~~4 小时前
【Linux驱动开发IMX6ULL】使用NXP MfgTool 烧写系统到eMMC
linux·运维·驱动开发