【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:

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" ]
RUN apk update && \
    apk add -U tzdata

Start command

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

Start command

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.