Configure time zone in Docker (transfer)

Because there is a business in the project, it is necessary to obtain the current time and the status of the goods participating in the event. However, the total query results were not obtained. Later, it was found that the time query of mysql was incorrect, because the time of mysql was 8 hours late. Because mysql is installed in docker, all the final reason is that the timezone of docker is not consistent with the current time. The following is the method of reprinting and modifying the docker time zone

 

Playing  Docker  has been very fun recently, and all the company's production environment has become a Docker deployment. Because Base Image is basically used by Docker, most of the time settings in  Etc/UTCit are the standard UTC time, so it is necessary to simply adjust it to become China Standard Time.

If a container has been created, you can directly access the container and use the command line to change the time zone:

First enter the corresponding containerid through the following command: (docker ps can get the CONTAINER ID)

1
# docker exec -ti containerid bash

Then execute the following command in the container:

1
2
# echo "Asia/Shanghai" > /etc/timezone
# dpkg-reconfigure -f noninteractive tzdata

You can see similar output on the screen:

1
2
3
Current default time zone: 'Asia/Shanghai'
Local time is now:      Thu Feb  5 10:55:04 CST 2015.
Universal Time is now:  Thu Feb  5 02:55:04 UTC 2015.

We can see that the local time has become  CST, that is  CST – China Standard Time, so that our time zone modification has been completed. The reason why we use  noninteractive it is to facilitate our integration  Dockerfile and use, such as:

1
2
RUN echo "Asia/Shanghai" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

In this case, we can set the time zone into our own Image, and we don't need to run the time zone setting once for each container.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327039953&siteId=291194637