localtime of shared hosting ( method 1 )
When creating a container, specify the startup parameters, mount the localtime file into the container, and ensure that the time zones used by the two are consistent.
docker run --name <name> -v /etc/localtime:/etc/localtime:ro ....
docker cp /etc/localtime:[container ID or name]/etc/localtime
After completion, use the date command to view the current time.
However, the time of the program running in the container may not be updated. For example, for the MySQL service running in the container, after updating the time, check the time of MySQL through sql
It can be found that the time has not changed.
At this time, you must restart the mysql service or restart the Docker container, so that mysql can read the changed time.
Create a custom dockerfile ( method 3, recommended )
Create a dockerfile file, in fact, there is no content, it is to customize the time format and time zone of the image.
ENV TZ=Asia/Shanghai #或者PST8PDT等,你需要的时区。
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone