[英]Set host time from within docker container
How can I set the system host time from inside a docker container? 如何从Docker容器内部设置系统主机时间?
My goal is to expose a very simple REST API that I can use to set the system host time. 我的目标是公开一个非常简单的REST API,我可以使用它来设置系统主机时间。 The REST service will run inside the container. REST服务将在容器内运行。
By default Docker container doesn't allow access to system clock of the host. 默认情况下,Docker容器不允许访问主机的系统时钟。
However, if after careful consideration you're fine with your container having access to this capability, you can explicitly allow this capability on Linux using "--cap-add=SYS_TIME" option of "docker run" command when creating you container: 但是,如果经过仔细考虑,您的容器可以使用此功能,则可以在创建容器时使用“ docker run”命令的“ --cap-add = SYS_TIME”选项在Linux上明确允许使用此功能:
# docker run --cap-add=SYS_TIME -d --name teamcity-server-instance -v /opt/teamcity/data:/data/teamcity_server/datadir -v /opt/teamcity/logs:/opt/teamcity/logs -p 80:8111 jetbrains/teamcity-server
Then, you can change the time from inside the running container: 然后,您可以从正在运行的容器内部更改时间:
# docker exec -it teamcity-server-instance /bin/bash
# date +%T -s "15:03:00"
15:03:00
#
Reference documentation: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities 参考文档: https : //docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.