Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda