Docker Community Forums

Share and learn in the Docker community.

Is it possible to change time dynamically in docker container?

swarm
dockerhub
build
docker

(Loganathan123) #1

Our scenario is we have been using .sh file to install install docker and deploy respective services as well.
Is there some other way of setting time explicitly when starting container?
Any help could be highly appreciated…


(Mikma) #2

How you change the system timezone depends on the linux distribution. On Debian, Ubuntu and other Debian based dists you use dpkg-reconfigure tzdata. But many tools reads the TZ environment variable. It may be enough setting it.

export TZ=GMT


(Loganathan123) #3

Thanks for quick response.no need to set timezone ,our scenario is we have been using .sh file to install install docker and deploy respective services as well.
Is there some other way of setting time explicitly when starting container?
Any help could be highly appreciated…


(Loganathan123) #4

No need to set timezone ,our scenario is we have been using .sh file to install install docker and deploy respective services as well.
Is there some other way of setting time explicitly when starting container?
Any help could be highly appreciated…


(Minherz) #5

As well as I know the time in container is same to the time of the host machine. There is no easy way to customize it because a container does not has its time service. You might think about creating a base image with some dummy time service and build your images from it. I never tried it though.


(Eric Smalling) #6

If you are asking how to set the host OS’s clock from inside a container, you would need to relax security on your container by adding the --cap-add SYS_TIME flag to your container at startup.

ie: docker run --rm -it --cap-add SYS_TIME alpine date -s 12:00

Of course, this means that any process in the container can do that to so beware.