docker container created time error and date error and time zone error

  • 2020-06-15 10:37:21
  • OfStack

A few days ago, when I was testing the application's functionality, I found that the data create_time or update_time fields in the database were always wrong. Other data was normal, only the time field was wrong.

Enter linux server view, also without any exception, then I think may be docker container, into the container, check the system time, indeed as expected with the host machine is different, the time in the online checked 1 while data after know the answer, time zone setting problem, 8 time zones to the east area of China, but and other countries may be different, if no modifications when creating container, time zone may not be the east eight area, so will appear this kind of similar problems.

Treatment method:


ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

Add the above Settings to the Dockerfile file where you created the container. Create the container again, and you will see that the system time is now displayed as the time in zone 8 east.


Related articles: