Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda