Recently, when I was using Docker to deploy a Java application, I found that the time zone was wrong. Using JDK to get the current time was 8 hours slower than the standard time zone. Solution:Solution 1. Modify DockerfileSet the time zone of the Alpine Linux system. Find the documentation of Alpine Linux and learn that the time zone can be set through the tzdata package. When building the Docker image, add this sentence to the Dockerfile: RUN apk --update add tzdata && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone && \ apk del tzdata && \ rm -rf /var/cache/apk/* Complete Dockerfile FROM openjdk:8-jre-alpine3.9 RUN apk --update add tzdata && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone && \ apk del tzdata && \ rm -rf /var/cache/apk/* # copy the packaged jar file into our docker image COPY application.jar /application.jar Document link: wiki.alpinelinux.org/wiki/Setting… Solution 2. Set the JVM's system default time zoneWhen starting the Docker image, set the time zone by setting the user.timezone JVM environment variable java -jar -Duser.timezone=Asia/Shanghai app.jar Solution 3. Mount the host machine’s time zone file into the Docker containerThe cluster solution uses K8S. When deploying, mount the host's time zone file into the Docker container. apiVersion: apps/v1 kind: Deployment metadata: name: SERVICE_NAME spec: replicas: 1 selector: matchLabels: app: SERVICE_NAME template: metadata: labels: app: SERVICE_NAME spec: containers: - name: SERVICE_NAME image: IMAGE_TAG imagePullPolicy: Always ports: - containerPort: 80 volumeMounts: - name: tz-config mountPath: /etc/localtime volumes: - name: tz-config hostPath: path: /etc/localtime Check if it is running normally date -R Reference Documents: quaded.com/docker-apli… blog.csdn.net/jeikerxiao/… This is the end of this article about solving the time zone problem of Docker Alpine image. For more relevant content about Docker Alpine image time zone, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: An in-depth summary of MySQL time setting considerations
>>: Implementation code for adding slash to Vue element header
Preface Before we start explaining the principle ...
Most of this article refers to other tutorials on...
Table of contents Preface 1. Custom focus command...
Fault description percona5.6, mysqldump full back...
1. IT Mill Toolkit IT Mill Toolkit is an open sou...
A reader contacted me and asked why there were pr...
Table of contents 1. Picture above 2. User does n...
Here are the detailed steps: 1. Check the disk sp...
Pre-installation work: Make sure vmware workstati...
Preface MySQL slow query log is a function that w...
To do MySQL performance adjustment and service st...
Find the problem Today, when I tried to modify th...
1. Function : Allows the parent component to inse...
Table of contents Preface 1. What is phantom read...
Preface Generator functions have been in JavaScri...