Update docker-contanier jre timezone

2019-09-07 06:43发布

问题:

According to here https://stackoverflow.com/a/40416306/6804200

i updated my local ubuntu jre date (os date was already true). But when i run application, date is still as old one.

I looked Application server in Docker - war deployment with IntelliJ

https://runnable.com/docker/java/dockerize-your-java-application

here but they dont do as i wanted.

I want to change jre of container which runs the app

because this

params.put("createdDate", persisted.getCreatedAt().
now(ZoneId.of(Constants.TURKEY_ZONE)).
format(DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT)));

brings wrong date. It is one hour before.

I need to do

java -jar tzupdater.jar -l file:///home/vegan/Downloads/tzdata2016g.tar.gz

as i do in my local.

OS is ubuntu. Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-34-generic x86_64) there are these images

jhipster/jhipster-alerter  
jhipster/jhipster-console   
jhipster/jhipster-registry   
mongo rabibtmq, 
vimagick/pure-ftpd 
and our company image about 1.8 gb.

there are around 10 12 microservices when project is app. i want to change something inside code, not starting changing start options of docker

回答1:

Can't say about docker by yes in java you can do below in some common class or in all classes where you create date object.

TimeZone.setDefault(TimeZone.getTimeZone("IST")); // IST is for timezone you want to set

Then in case of Date dt=new Date(); it will contain date as per IST timezone .



回答2:

  1. You need to run tzupdater.jar inside the container(docker exec -it container_id bash and then execute the updater), because container has it's own jre.
  2. Also you need to build new docker image with updated jre that will contain latest file based time zone database(https://www.iana.org/time-zones).
  3. If it is critical for you to have accurate Timezone offsets all the time, consider using some timezone webservice. See here.