How does a container know the exact time (UTC timezone) from host machine? #45691
-
Description[Exact UTC Time in a Container] Hello Everyone. I have a question about the container time:
I have not got any descriptions in doc.docker.com about the detailed principles in this topic. Thank you all. ReproduceI just use busybox to have the test.
The timezone is CST and time is correct in my host machine.
When I check the time in the container, I have found it is UTC time. Why is it UTC time?
Expected behaviorI expect the time in a container should also be CST time. docker versionClient: Docker Engine - Community
Version: 24.0.0
API version: 1.41 (downgraded from 1.43)
Go version: go1.20.4
Git commit: 98fdcd7
Built: Mon May 15 18:51:37 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 20.10.1
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: f001486
Built: Tue Dec 15 04:35:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.21
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc:
Version: 1.1.7
GitCommit: v1.1.7-0-g860f061
docker-init:
Version: 0.19.0
GitCommit: de40ad0 docker infoClient: Docker Engine - Community
Version: 24.0.0
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.10.4
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.17.3
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 2
Running: 2
Paused: 0
Stopped: 0
Images: 3
Server Version: 20.10.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc version: v1.1.7-0-g860f061
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.88.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.607GiB
Name: VM-4-2-centos
ID: W7CA:BPIF:V2UB:HENA:WZYF:NCFV:Y3SR:BDTX:YQK7:LXAQ:UWUW:EGRW
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://hub-mirror.c.163.com/
https://mirror.baidubce.com/
Live Restore Enabled: false Additional InfoI hope docker developers or someone could provide me more detailed information in the docker source code. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
A container is not a VM -- it's just a namespaced slice of resources on the same kernel as your 'host' machine. In this case, timezones are a construct of userspace (more or less); so timezones inside the container are defined by the container rootfs (filesystem) and not the 'host' filesystem. In the future, we can create a time namespace for the container (https://manpages.ubuntu.com/manpages/impish/man7/time_namespaces.7.html); this namespace defaults to the same time as the root ('host') time namespace. Note that what is namespaced is a subset of clocks (mostly, time since boot/monotonic clocks); the wall clock is not virtualized by time namespaces. |
Beta Was this translation helpful? Give feedback.
A container is not a VM -- it's just a namespaced slice of resources on the same kernel as your 'host' machine. In this case, timezones are a construct of userspace (more or less); so timezones inside the container are defined by the container rootfs (filesystem) and not the 'host' filesystem.
In the future, we can create a time namespace for the container (https://manpages.ubuntu.com/manpages/impish/man7/time_namespaces.7.html); this namespace defaults to the same time as the root ('host') time namespace.
Note that what is namespaced is a subset of clocks (mostly, time since boot/monotonic clocks); the wall clock is not virtualized by time namespaces.