Modifying a Container Time-Zone

The default time zone for any Docker container is UTC. In the case where you want the Docker container's time-zone to be in sync with the host machine's time-zone, you can apply these changes either in the Docker file or in the Docker-Compose YAML file.

Docker containers always use the system clock of the host machine but it sets its time-zone as UTC. The following steps are an example of changing the time zone for a TIBCO OPE Server container.

Procedure

  • You can modify a container's time zone with either of the following two ways:

    • This approach can be applied when you have not created any images. Open the $OPE_HOME/ docker/ope/6.0.0/Dockerfile in a suitable editor and modify the file as shown:

      Copy
      FROM tibco/base:1.0
      COPY ope $OPE_HOME/ope ENV TZ-Asia/Kolkata
      COPY config $OPE_HOME/config
      RUN ln -snf /user/share/zoneinfo/$TZ etc/localtime "echo $TZ > /etc/timezone 
      RUN  chmod 777 $OPE_HOME/ope/standalone/bin/* \
       && chmod -R a+w $OPE_HOME/ope/standalone/config
      USER root
                   
      ENTRYPOINT ["sh","-c", 
      "$OPE_HOME/ope/standalone/bin/start.sh -
      XX:MinRAMPercentage=$min_ram_percentage -
      XX:MaxRAMPercentage=$max_ram_percentage --run=FG"]

      EXPOSE 8090

      In this example, the following has been modified:
      ENV TZ=Asia/Kolkata
      RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ /etc/timezone
      Here you have to change the value of the TZ variable as per your time zone (in the example, the time zone is Asia/Kolkata).

    • This approach can be applied if your images are already created and now you want to change the container time zone at runtime. Open $OPE_HOME/docker/docker-compose-run-ope- service.yml in a suitable editor and modify the file as shown:

      Copy
      version: "3" services:ope:image: "tibco/ope:${OPE_VERSION_TAG}" ports:"${HOST_OPE_SERVICE_PORT}:8090"volumes:"${HOST_LOG_ROOT_LOCATION_DIR_PATH}:/opt/tibco/ope/6.0.0/ope/standalone/logs"environment:- "TZ=Asia/Kolkata"command: sh -c "ln -snf/user/share/zoneinfor/$TZ /etc/localtime && echo $TZ> /etc/timezone"

      In this example, the following has been modified:
      environment:
      - "TZ=Asia/Kolkata"

      Copy
      command: >
      sh -c "ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/ timezone"

      Here you have to change the value of the TZvariable as per your time zone (in the example, the time zone is Asia/Kolkata).