Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change system date time in Docker containers without impacting host

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.

like image 921
user1717055 Avatar asked Mar 10 '15 20:03

user1717055


People also ask

How do I change the date and time in a Docker container?

The easiest way to change the time in a Docker container is to change the time using 'date' command after connecting to the container. Though the time zone change usually reflects immediately, in some cases, the container needs a restart for the time to change.

How do I change the timezone in my Docker container?

The directory /usr/share/zoneinfo in Docker contains the container time zones available. The desired time zone from this folder can be copied to /etc/localtime file, to set as default time. The containers created out of this Dockerfile will have the same timezone as the host OS (as set in /etc/localtime file).

Does Docker images have a different state and change with time?

Docker images are a little bit different from a virtual machine snapshot, though. For starters, Docker images can't ever change. Once you've made one, you can delete it, but you can't modify it. If you need a new version of the snapshot, you create an entirely new image.

What timezone does Docker use?

Docker containers don't inherit the host's timezone, so you can run into unexpected scheduling issues that wreak havoc with your application. The container is using the UTC timezone, creating a one hour difference between the two times.


1 Answers

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.

like image 154
user1717055 Avatar answered Sep 28 '22 07:09

user1717055