IBM Support

Time zone mismatch between Docker container and Linux host

Question & Answer


Question

How to synchronize the time zone between Docker and the Linux hosts.

Answer

Assuming the containers are already started,we should modify this directly inside the container.

For example ,  IFEAppNode on a vm

First, check the /etc/localtime on the host vm by running command "ll /etc/localtime"

The host vm is using ../usr/share/zoneinfo/Asia/Shanghai, this info will be used reset the timezone inside the container.

Second, check the /etc/localtime inside the docker container , for example "IFEAppNode" by running below command.
    docker exec -it IFEAppNode /bin/bash -c "ls -al /etc/localtime"

The container is using ../usr/share/zoneinfo/UTC

Third, enter the container and re-link the /etc/localtime, and restart the container(You need do this for all application containers , using "docker ps " to check).
    docker exec -it IFEAppNode bash
    mv /etc/localtime /etc/localtime.bk
    ln -s ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime            (The same one we checked in First step)
    exit 

Now, when you check the "date" in the host and the container, they should be the same.
    date
    docker exec -it IFEAppNode /bin/bash -c "date"

Lastly, after re-linking the /etc/localtime for all containers it is advisable to follow the instructions below to re-apply network setting after restarting  those containers.

---
    Applying calico network settings after a system reboot or a container restart
    https://www.ibm.com/support/knowledgecenter/en/SSMNA6_2.5.0/com.ibm.ifeop.doc/install_docker/t_iot4eu_apply_cal_net_set.html

---

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSMNA6","label":"IBM Maximo Asset Performance Management for Energy & Utilities On-Premise"},"Component":"","Platform":[{"code":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Document Information

Modified date:
01 November 2018

UID

ibm10738215