Docker Timezone Settings

【Notes】Docker Timezone Settings

If we want to Dockerset hostthe same time zone internally, how should we set it?

Quick Start

Many people on the Internet said that containeryou can add the following command at startup:

  • Method 1:

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

  • Method 2:

    -and “TZ=Asia/Taipei”

But sometimes it works, and sometimes it doesn’t work. Why? It depends on what you usedocker image

Use alpinethe version

dockerfile

 dockerfile 364 B 
12345678910111213
FROM openjdk:12-alpine
VOLUME /tmp

RUN apk update && \
    apk add -U tzdata

ADD build/libs/sb-crawler-0.0.1-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'

EXPOSE 6565
ENV JAVA_OPTS=""
ENV SPRING_PROFILES_ACTIVE=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/urandom -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar /app.jar" ]
  • We dockerfileadded the installation tzdatainstructions in
RUN apk update && \
    apk add -U tzdata

Start command

  • Add to-v /etc/localtime:/etc/localtime:ro
docker run --name sb-crawler -d -h sb-crawler -p 8081:8081 -e SPRING_PROFILES_ACTIVE=prod -v /home/ec2-user/log/sb-crawler:/log -v /etc/localtime:/etc/localtime:ro registry.gitlab.com/sportsbook1/sb-crawler:$CI_COMMIT_SHORT_SHA

Use alpinea non-

The disadvantage is that it is alpinemuch larger than the previous version and takes more time (push image)

dockerfile

  • Used imageforopenjdk:12

Start command

  • Add to-e "TZ=Asia/Taipei"

That’s it for today’s notes. If you have any questions, let me know!