Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync the time of a java application running on docker container?

I am docker file like this:

FROM anapsix/alpine-java:jre8 
ADD service-god-sac-1.0.0-SNAPSHOT.jar app.jar 
ENTRYPOINT ["java", "-Xmx64m", "-XX:MaxMetaspaceSize=64m", "-jar", "/app.jar"]

When I compile and deploy the app settint the time using this:

-v /etc/localtime:/etc/localtime:ro

I notice that the host time and containter time are syncronized, but the logs of the app shows a diferent time, the UTC time. How can I sync the host machine, the container and the java app with the same time?

like image 846
Rys Avatar asked Sep 25 '22 19:09

Rys


1 Answers

Mapping localtime and timezone works perfectly.

Example:

docker run -d -v /var/lib/elasticsearch:/var/lib/elasticsearch -v /etc/localtime:/etc/localtime:ro -v /usr/share/zoneinfo/America/Buenos_Aires:/etc/timezone:ro -p 80:80/tcp -p 9200:9200/tcp -p 514:514/udp petergrace/elk

like image 113
Rys Avatar answered Sep 29 '22 03:09

Rys