Using docker-compose to set container time zones

I have a docker file in which there are several Docker files for creating containers. I do not want to edit my Dockerfiles to set time intervals, because they can change at any time by members of my team, and I have a docker-compose.override.yml file to make changes to the local environment. However, one of my containers (based on selenium) does not seem to give out the host time zone, and this creates problems for me. Based on this, I want to use time zones in all containers. In my dockerfiles right now I'm doing

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

And everything works fine. How to duplicate the same command in docker-compose syntax?

+14
docker containers docker-compose dockerfile devops
source share
3 answers
 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: I didn’t ask a question, but I just added exec my-main-application to show how the main process will be set. exec is important here to make sure my-main-application gets Ctrl-C (SIGINT / SIGKILL).

+17
source share

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

 ipchanger: image: codertarasvaskiv/ipchanger:raspberry volumes: - "/etc/localtime:/etc/localtime:ro" 
  • ro - means that the container can only read from / etc / localtime of the host machine.
0
source share

This is a simple solution:

 environment: - TZ=America/Denver 
0
source share

All Articles