Reputation: 8461
How can I set the system host time from inside a docker container?
My goal is to expose a very simple REST API that I can use to set the system host time. The REST service will run inside the container.
Upvotes: 0
Views: 2150
Reputation: 979
By default Docker container doesn't allow access to system clock of the host.
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 -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
Upvotes: 1