Home > Software engineering >  How to set the correct time in spring boot logs with docker
How to set the correct time in spring boot logs with docker

Time:02-18

Good afternoon. I am working with docker containers and an application in spring boot, but I am having a problem with the time zone in the registry, I configured the time zone at the docker container level to be America/Caracas, however, when I start the container I am observing that there are 4 ahead in the time zone. Configure my time zone through kubernetes and the directory /etc/localtime --> America/Caracas, as shown below:

Dockerfile Images

FROM adoptopenjdk/openjdk11:alpine-jre
ADD FindAccountNumber-0.0.1-SNAPSHOT.jar /home/app.jar
ADD srvdevrma1.jks /etc/letsencrypt/srvdevrma1.jks
ADD tmt097.jks /etc/letsencrypt/tmt097.jks
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/home/app.jar"]

Kubernetes Deploy:

  - name: find-account-number-srvdevrma1
    image: find-account-number:v2
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - mountPath: /etc/localtime
      name: tz-caracas     
    resources:
      limits:
        cpu: "300m"
        memory: "350Mi"
      requests:
        cpu: "200m"
        memory: "300Mi"
    ports:
    - containerPort: 8081

  volumes:  
    - name: tz-caracas
      hostPath:
        path: /usr/share/zoneinfo/America/Caracas   

Date in my container:

enter image description here

Registers in My Application Spring Boot

enter image description here

What could be happening, should I configure something at the level of my spring boot application in code?

CodePudding user response:

Try to add in your application.yml these lines:

logging:
  pattern:
    dateformat: yyyy-MM-dd HH:mm:ss.SSS,America/Caracas

Or the equivalent configuration for the application.properties

logging.pattern.dateformat=yyyy-MM-dd HH:mm:ss.SSS,America/Caracas
  • Related