Modifying a Container Time-Zone

The default time-zone for any Docker container is UTC. In the case where you want your 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 timezone for an OMS server container.

Procedure

  • You can modify a container's timezone with either of the following two ways:
    • This approach can be applied when you have not created any images. Open the $AF_HOME/docker/fom-oms/4.0.0/Dockerfile in a suitable editor and modify the file as shown:
      FROM tibco/base:1.0
      
      COPY omsServer $AF_HOME/omsServer
      
      RUN chown -R tibuser:tibuser /home/tibuser/ \
      	" chmod -R a+x $AF_HOME/omsServer/standalone/bin
      
      ENV TZ-Asia/Kolkata
      RUN ln -snf /user/share/zoneinfo/$TZ etc/localtime "echo $TZ > /etc/timezone
      
      USER tibuser
      
      ENTRYPOINT [*/home/tibuser/tibco/af/4.0/omsServer/standalone/bin/start.sh", "--run=FG"]
      
      EXPOSE 9091

      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 need to change the value of the TZ variable as per your timezone (in the example, the timezone is Asia/Kolkata).

    • This approach can be applied if your images are already created and now you want to change the container timezone at runtime. Open $AF_HOME/docker/docker-compose-run-oms.yml in a suitable editor and modify the file as shown:
      version: "3"
      
      services:
      	tibco-fom-oms:
      		image: "tibco/fom-oms:${FOM_VERSION_TAG}"
      		ports:
      			- "9091"
      		volumes:
      			- "${HOST_LOG_ROOT_LOCATION_DIR_PATH}:/home/tibuser/tibco/af/4.0/omsServer/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"
      command: >
        sh -c "ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone"
      

      Here you need to change the value of the TZ variable as per your timezone (in the example, the timezone is Asia/Kolkata).