Reputation: 281
Is it possible to change the system time in Docker containers without changing the host itself?
We are using Docker containers for testing which are sometimes time sensitive. I notice that any changes made to the host time are reflected to the Docker containers right away (which makes sense since they are using the same kernel). I am hoping, however, that Docker provides a way for you to somehow override the start time of the container and move from thereon.
Upvotes: 21
Views: 18983
Reputation: 10848
As described in detail here the solution that I follow is to run docker on top of a VM and automate the whole process of changing-vm-time, running-vm and running-container, via vagrant.
Upvotes: 2
Reputation: 281
Just a follow up for those looking to have different datetime in Docker containers, https://github.com/wolfcw/libfaketime should probably be able to do the job.
Upvotes: 5
Reputation: 57
Simple:
Steps:
First check the localtime of the docker container:
[root@locdb oracle]# zdump /etc/localtime
/etc/localtime Tue May 22 13:59:40 2018 UTC
Check the timezones like below:
[root@locdb oracle]# zdump /usr/share/zoneinfo/* | tail -10
/usr/share/zoneinfo/UTC Tue May 22 14:01:21 2018 UTC
/usr/share/zoneinfo/Universal Tue May 22 14:01:21 2018 UTC
/usr/share/zoneinfo/W-SU Tue May 22 17:01:21 2018 MSK
/usr/share/zoneinfo/WET Tue May 22 15:01:21 2018 WEST
/usr/share/zoneinfo/Zulu Tue May 22 14:01:21 2018 UTC
/usr/share/zoneinfo/iso3166.tab Tue May 22 14:01:21 2018
/usr/share/zoneinfo/posix Tue May 22 14:01:21 2018
/usr/share/zoneinfo/posixrules Tue May 22 10:01:21 2018 EDT
/usr/share/zoneinfo/right Tue May 22 14:01:21 2018
/usr/share/zoneinfo/zone.tab Tue May 22 14:01:21 2018
Copy the one that you need for example :
cp /usr/share/zoneinfo/UTC /etc/localtime
Upvotes: 0