Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
How do you change the Docker container TZ in spring?

I am using frolvlad/alpine-oraclejdk8 base image as recommended by spring: https://spring.io/guides/gs/spring-boot-docker/

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

I am running the image with -e TZ=/usr/share/zoneinfo/Europe/Paris

I am setting the env TZ but this doesn't change the TimeZone in my container.

How do you change the timezone for this image?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Alpine Linux does not install timezone files by default to minimize the size of the Docker image.

You need to explicitly install the tzdata package and copy the zoneinfo file according to the timezone you want to set.

An example for Dockerfile is as follows:

FROM frolvlad/alpine-oraclejdk8:slim

RUN apk --update add tzdata && \
    cp /usr/share/zoneinfo/Europe/Paris /etc/localtime && \
    apk del tzdata && \
    rm -rf /var/cache/apk/*

Build the image:

$ docker build -t tztest .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM frolvlad/alpine-oraclejdk8:slim
 ---> 00d8610f052e
Step 2 : RUN apk --update add tzdata &&     cp /usr/share/zoneinfo/Europe/Paris /etc/localtime &&     apk del tzdata &&     rm -rf /var/cache/apk/*
 ---> Running in 5b6a014fdaf3
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tzdata (2016i-r0)
Executing busybox-1.25.1-r0.trigger
OK: 14 MiB in 15 packages
(1/1) Purging tzdata (2016i-r0)
Executing busybox-1.25.1-r0.trigger
OK: 10 MiB in 14 packages
 ---> 6c379ddd4186
Removing intermediate container 5b6a014fdaf3
Successfully built 6c379ddd4186

Check date of the container:

$ docker run -it --rm tztest date
Thu Mar  9 16:34:54 CET 2017

EDIT:

If you want to set timzone at runtime not on build, install the tzdata package and do not delete on build:

FROM frolvlad/alpine-oraclejdk8:slim

RUN apk --no-cache add tzdata

Build the image:

$ docker build -t tztest .

And then, you can set environment variable TZ at runtime:

$ docker run -it --rm -e TZ="Europe/Paris" tztest date
Fri Mar 10 01:59:27 CET 2017
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!