Docker의 timezone 과 java application 의 timezone의 sync를 맞추자! 

혹은.. 서버의 timezone과 java application의 sync...

 

docker의 timezone을 설정하고, 

spring boot인 application 을 띄웠는데..

 

 

다음과 같이 localtime을 지정해주고 docker를 띄워주면

 

docker run -d -v /etc/localtime:/etc/localtime:ro

 

/ # date
Thu Mar 12 06:55:37 UTC 2020

date 명령어로 timezone이 잘 바뀐걸 확인 할 수 있다.

 

 

그런데..

spring의 log를 보면 timezone의 시간과 안맞는 것이다..

 

그래서 검색해보니 

log의 시간은 jvm의 시간을 물고가는데 

혹은, java application 단에서도 jvm의 시간을 가져오기 때문이다.

 

그래서 하단의 stack overflow를 보고 해결하였다. 한가지 옵션을 더주니 해결 되었다.

 

docker run -d -v /etc/localtime:/etc/localtime:ro -v /usr/share/zoneinfo/Asia/Seoul:/etc/timezone:ro

 

그리고 다시 재기동~ 후 확인해보니

date도, log도 모두 같은 시간인걸 확인하였다.

 

 

그런데 저 명령어가 무슨 의미가 있어서 잘되는지 알고 싶은데.. 

찾다가 정확하게 이해는 못하였다.

 

하단 github 참조

 

As I experience it, containers use their internal timezone, not the timezone of their host OS.

 

So, let's unravel this a little bit (hopefully).

  • containers share the kernel
  • the kernel tracks the "current time" (note this is "time", not "timezone"), and it is tracked simply as the "number of seconds since the epoch (1970-01-01 00:00:00 UTC)" (hence the name, "Unix Timestamp")
  • userspace (which includes tools like date) has a notion of "timezone", and it usually comes from "/etc/localtime" (but this does sometimes depends on the utility, some read "/etc/timezone" instead, and some update "/etc/localtime" from the contents of "/etc/timezone")

The Gentoo Wiki's "System time" entry also has some great information that helps untangle

 

 

저 말을 해석해보면.

컨테이너는 host OS의 timezone이 아니라 각각 내부의 timezone을 사용하고 

 

그아래 문구를 해석해보자면.. 결국 timezone은 여러군데서 읽어온다는 뜻인거 같다... 허허

 


 

 

그리고 찾다보니 docker가 아닌 서버에서도 이런 경우가 있는데 다음 블로그에 그 방법이 자세히 나와있다.

 

https://irontooth.tistory.com/47

 

java Calendar 시간과 서버시간 불일치 처리

1) Calendar runTimeCal = Calendar.getInstance(); System.out.println ("현재 타임존 : " + runTimeCal.getTimeZone().getDisplayName() ); TimeZone tz = TimeZone.getTimeZone("GMT+09:00"); runTimeCal.setTi..

irontooth.tistory.com

 

java -jar -Duser.timezone=Asia/Seoul 

해당방법처럼 매번 기동할때마다 이렇게 설정해주던가.. 아니면 start shell에 입력해주면 될거같다

아니면 

WAS에서 하는 방법도 있다.

 


 

참고 : 

 

https://stackoverflow.com/questions/34534079/how-to-sync-the-time-of-a-java-application-running-on-docker-container

 

How to sync the time of a java application running on docker container?

I am docker file like this: FROM anapsix/alpine-java:jre8 ADD service-god-sac-1.0.0-SNAPSHOT.jar app.jar ENTRYPOINT ["java", "-Xmx64m", "-XX:MaxMetaspaceSize=64m", "-jar", "/app.jar"] When I co...

stackoverflow.com

 

https://github.com/moby/moby/issues/3359

 

container timezone · Issue #3359 · moby/moby

As I experience it, containers use their internal timezone, not the timezone of their host OS. I currently work around this issue by providing a start script that takes a typezone parameter which i...

github.com

 

'DEVELOP > DevOps' 카테고리의 다른 글

내가 헷갈려서 쓰는 Git..기능  (0) 2019.07.12

Git을 오래 사용하였지만 

commit.. pull.. merge..push...

이외에는 잘 사용하지 않았던거 같다..

(사실 지금도 그렇당 ㅎㅎ)

 

쓰다보니 다른기능도 

알아두면 좋을거같은데..

매번 내가 헷갈려서 쓰는 포스팅,, ㅎ1ㅎ1

 

 

 

1. amend : commit 수정

$ git add sample.txt
$ git commit --amend

이걸 쓰는건 못봤지만.. Git 홈페이지에 있길래 

쓸진 모르겠당

 

2. revert : commit 취소

$ git revert HEAD

제일 많이 쓰는것중 하나,,! intelliJ에서는 undo도 가능하다.

둘다 써보니 revert는 취소하는 comiit을 하나 더 치는거고 undo는 아예 없애는것이 다른점이다.

 

3. reset : master 브랜치 앞의 commit을 삭제

$ git reset --hard HEAD~~

실수로 reset을 잘못 했을 경우 , 'ORIG_HEAD'로 reset전 상태로 되돌릴 수 있다.

$ git reset --hard ORIG_HEAD

 

4. cherry-pick : 특정 commit을 선택해서 반영하기 

체리나무에 달려 있는 체리를 하나씩 골라 따듯이,, 커밋들을 골라서 반영하는것이 체리픽!

이건 잘 쓸거 같당

 

$ git checkout master
Switched to branch 'master'
$ git cherry-pick 99daed2

 

5. rebase : 여러개의 commit을 반영하기 

$ git rebase {branch name}

브랜치에 여러 커밋을 하나로 합쳐준다.

 

rebase -i 옵션을 붙여서 commit 순서를 바꾸거나 첨삭 할 수 있다. 

$git rebase -i HEAD~3

 

6. merge : 두개의 branch를 하나로 합치기

+ Recent posts