简体   繁体   English

从Docker容器中设置主机时间

[英]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.

相关问题 从Dockers容器中访问主机上的MySQL数据库 - Accessing MySQL Database on Host Machine from within Dockers Container 在 docker 容器中构建 REST api 的材料 - Material on Building a REST api from within a docker container 无法从另一个Docker容器访问Docker容器中的REST端点 - Cannot access REST endpoint in docker container from another docker container 如何在运行时给Docker容器提供端口号? - How to give port number for docker container at run time? 一段时间后docker容器中的服务停止 - Service inside docker container stops after some time 使用Apache Camel在Docker容器中调用服务时响应时间长 - Long response time when calling a service in a Docker container with Apache Camel 使用Mongo REST API从MongoDB Docker容器检索json - Using Mongo REST API to retrieve json from MongoDB Docker container 您如何将文件(从URL)上传到Docker容器? - How do you upload a file (from url) to a Docker container? 从一个 docker 容器到另一个容器的 REST 请求失败 - REST request from one docker container to another fails Angular 应用程序无法与来自 Nginx ZC5FD214CDD0D2B3B4272E73B022BA5 的 API 通信 - Angular App Not Communicating with API from Nginx Docker Container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM