Solution to docker time inconsistency: 1. Add the "-v /etc/localtime:/etc/localtime" option when running docker run; 2. Copy the time zone information to the container.
The operating environment of this article: ubuntu 18.04 system, Docker version 20.10.11, Dell G3 computer.
docker What should I do if the time is inconsistent?
Solution to the inconsistency between the docker container time and the local time:
The inconsistency between the docker container and the system time is because the native time zone of the docker container is 0 time zone
First method: mapping at startup
Run docker run and add the -v /etc/localtime:/etc/localtime option, as follows:
docker run -d -p 8080:80 -v /etc/localtime:/etc/localtime nginx
Second: Copy time zone information to the container
If the local time zone is correct, directly:
docker cp /etc/localtime nginx:/etc/localtime
If the local time zone is incorrect:
docker cp /usr/share/zoneinfo/Asia/Shanghai nginx:/etc/localtime
Recommended Study: "Docker Video Tutorial"
The above is the detailed content of What to do if docker time is inconsistent. For more information, please follow other related articles on the PHP Chinese website!