Using docker-compose to set containers timezones

≡放荡痞女 提交于 2019-12-02 20:33:48
version "2"

services:
  serviceA:
    ...
    environment:
      TZ: "America/Denver"
    command: >
      sh -c "ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && 
      echo $TZ > /etc/timezone &&
      exec my-main-application"

Edit: The question didn't ask for it but I've just added exec my-main-application to show how the main process would be specified. exec is important here to make sure that my-main-application receives Ctrl-C (SIGINT/SIGKILL).

This is simple solution:

environment:
  - TZ=America/Denver

The easiest solution would be share volume in docker-compose.yml like this

ipchanger:
  image: codertarasvaskiv/ipchanger:raspberry
  volumes:
    - "/etc/localtime:/etc/localtime:ro"
  • ro - means container can only read from /etc/localtime of host-machine.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!