Using docker-compose to set containers timezones

I have a docker-compose file running a few Dockerfiles to create my containers. I don’t want to edit my Dockerfiles to set timezones because they could change at any time by members of my team and I have a docker-compose.override.yml file to make local environment changes. However, one of my containers (a Selenium based one) seems to not pull host time zone and that causes problems for me. Based on that I want to enforce timezones on all my containers. In my Dockerfiles right now I do

ENV TZ=America/Denver
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

And everything works fine. How do I replicate the same command in docker-compose syntax?

  • Does Apache Mesos + Marathon support LXD cluster management?
  • Jenkins Job Builder not creating publishers
  • docker and image size limit
  • Bluemix Container status reads 'Networking'
  • How do I forward a docker-machine port to my host port on OSX?
  • How can i create a folder inside the shared volume with the correct permission in docker?
  • Where can I find the list of Docker format template variables?
  • Visual Studio docker app: error mounting source path
  • unable to pull any docker images on redhat 7.1
  • How to add my container's hostname to /etc/hosts?
  • Cannot use vim, vi, nano, yum inside docker container
  • Operation not permitted systemctl with docker + systemctl
  • One Solution collect form web for “Using docker-compose to set containers timezones”

    version "2"
          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).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.