O
O
Oleg Bugrov2016-12-16 11:54:09
linux
Oleg Bugrov, 2016-12-16 11:54:09

How to change date in docker container?

It is required to set the year 2027 in the container, OS - debian 8, issues
a command Or should the time be changed on the host machine? Although this is highly undesirable. UPD. In order to cut off the options for answers related to rights, here is a screen of the terminal
date --set 2027-12-16
date: cannot set date: Operation not permitted
95ad661c941941f5907de46924b5eded.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav, 2016-12-16
@mrakodav

Perhaps you should do it as root or with su/sudo? ;-)
Source :

That's not possible with Docker. Docker uses the same clock as the outside kernel. What you need is full virtualization which emulates a complete PC.
The sudo fails because it only makes you root of the virtual environment inside of the container. This user is not related to the real root of the host system (except by name and UID) and it can't do what the real root could do.
In you use a high level language like Python or Java, you often have hooks where you can simulate a certain system time for tests or you can write code which wraps "get current time from system" and returns what your test requires.

In other words, the date is not set because there are no root rights - if you believe the quote above, then in reality the root user in the container is a fiction, and only when using "real" root rights is it possible to change the date / time. Accordingly, if you can do anything with the date, then only by changing the time zone, which is acceptable from the point of view of logic, which is given for example here .
So from the looks of it, your path is either hacking into the environment you want to test with the modified date, or using more complete virtualization.

M
Maxim Moseychuk, 2016-12-16
@fshp

Maybe this will help you
manpages.ubuntu.com/manpages/trusty/man1/faketime....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question