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;'
相关推荐
播播资源13 小时前
CentOS系统 + 宝塔面板 部署 OpenClaw源码开发版完整教程
linux·运维·centos
学不完的13 小时前
Docker数据卷管理及优化
运维·docker·容器·eureka
lay_liu13 小时前
Linux安装redis
linux·运维·redis
曾经拒绝刘亦菲15 小时前
Clamav在麒麟V10离线安装指南
运维
志栋智能15 小时前
超自动化巡检:应对复杂IT环境的必然选择
运维·网络·安全·web安全·自动化
li星野15 小时前
[特殊字符] Linux/嵌入式Linux面试模拟卷
linux·运维·面试
hansaes15 小时前
第一章:容器到底是什么
docker
一直都在57217 小时前
深入理解 synchronized:到底锁的是谁?
运维·服务器
RisunJan17 小时前
Linux命令-mkbootdisk(可建立目前系统的启动盘)
linux·运维·服务器
Sst的头号粉丝17 小时前
Docker——compose
运维·docker·容器