Solve the problem of inconsistency between database time and server time under docker container

problem:

Use docker to install MySQL, but the time of the container is inconsistent with the server time, how to adjust?

Solution:

docker run --name mysql01 -p 3306:3306 -v /var/mysql/data:/var/lib/mysql -d -v /etc/localtime:/etc/localtime -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

Copy the system time to the container;
then use docker exec -it container name/bin/bash
input: date to check whether the time is consistent with the current one;

https://blog.csdn.net/herokoking/article/details/105075037 There are other ways in this post, but I didn't try it. If you are interested, you can check it out!

Guess you like

Origin blog.csdn.net/Curtisjia/article/details/106891712