Spring Cloud is based on Docker for packaging and deployment 6-Modify the time zone of the container

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 ....
Copy the localtime of the host ( method 2 )
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

select now() from dual;

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
After saving, use the docker build command to generate the image and use it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325482072&siteId=291194637