Hi, this is @chan_kaku This time, a problem occurred when the in-house tool was converted to Docker, so I will introduce the problem, the countermeasures taken this time, and the difficult points.
This time I had a problem with my Java application.
The problem was that at some point, the time to be persisted in the DB was made persistent by taking the current time with new Date ()
.
Until now, I didn't use Docker and depended on the timezone of the host server, so I was able to take time with JST and there was nothing wrong with it.
However, after converting this tool to Docker, there was a problem that the current time on this new Date ()
was shifted.
In the first place, I didn't know much about Docker and guessed that there was a problem with the code on the Java side.
However, as mentioned above, the current time was taken as new Date ()
, so that guess was wrong.
The next guess was the host server timezone. However, when I typed the date
command, it was displayed as JST
, so this was also missed.
I've run out of my possible guesses, so when I asked people familiar with Docker, I got the information that it seems that there is time inside Docker, and that this time may be off.
So, I entered Docker with the following command and checked the time zone in the Docker container in the same way.
docker run -t -i (Target docker image) /bin/bash → start docker and go inside
# date
Here, it was JST
as before.
When I was lamenting that all the measures had been exhausted here, a voice of a crane came from a certain person.
"Look at the contents of / etc / timezone
in Docker ~ "
Believing in this person, I entered Docker and looked at / etc / timezone
, and found that this was ʻUTC. So I modified the Dockerfile to change
/ etc / timezone to ʻAsia / Tokyo
as follows
ENV TZ="Asia/Tokyo"
RUN echo $TZ > /etc/timezone
//Descriptions other than timezone related are omitted
The reason why I changed it with echo this time is that the time zone of the time system was required to be JST due to the requirements of the tool, so I decided that this should be described in the Dockerfile.
I had a hard time in various places because I didn't have much knowledge about Docker, but I'm glad I solved it for the time being! We are waiting for Masakari, who says that these people are smarter.
Recommended Posts