I have created an Oracle Database Docker Image with the help of this link

SYSTIMESTAMP shows UTC time and not my local machine's time.

kaushik:~ knayak$ date
Fri Jun  8 17:46:35 IST 2018

select current_timestamp,systimestamp from dual;

CURRENT_TIMESTAMP                           SYSTIMESTAMP                      
------------------------------------------- ----------------------------------
08-06-18 05:47:51.742216000 PM ASIA/KOLKATA 08-06-18 12:17:51.742211000 PM GMT

How can I change the container's time to match with my time zone?

  • Always use UTC on the server! Use client specific NLS settings and application logic to display times in the applicable timezone(s) – Philᵀᴹ Jun 8 '18 at 13:52
  • Check documentation: CURRENT_TIMESTAMP returns time current time in your current session local time zone. SYSTIMESTAMP returns current time in time zone of the system on which the database resides (i.e. docker in your case). Thus change the time zone settings in docker. – Wernfried Domscheit Jun 11 '18 at 9:06

The problem is not with your database, it is the problem of the docker.

Docker has notorious problems with the time synchronization between the host machine and the virtual machines ("containers"...).

The simplest solution for the problem if you start the docker container with admin privileges (--privileged flag to docker run), and then use a time synchron tool inside the container to fix its time (ntpdate -s your.country.clock).

| improve this answer | |

Googled and tried several options and finally, what worked for me :-

Login as root user into the container:

docker exec -u 0 -it oracle-ee bash

Check for /etc/localtime file which would be pointing to UTC

bash# cd /etc
bash# ls -lrt localtime
lrwxrwxrwx 1 root root 25 May 26 12:56 localtime -> ../usr/share/zoneinfo/UTC

Remove the file and create a new softlink to point to the file corresponding to your local timezone.

bash# rm -f localtime
bash# ln -s /usr/share/zoneinfo/Asia/Kolkata localtime 

Exit the shell and restart the container.

docker restart <containername>

Verify the output from the query and it looks fine.

LOCALTIMESTAMP                 SYSTIMESTAMP                         
------------------------------ -------------------------------------
09-06-18 01:57:23.685610000 PM 09-06-18 01:57:23.685601000 PM +05:30

The commands or the localtime file may vary depending on the OS emulated by Docker. In my case, it was x86_64 GNU/Linux.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.