From 4b4312b290f1242bada2c573174748f7d25af2f4 Mon Sep 17 00:00:00 2001 From: Rohit Jnagal Date: Thu, 7 May 2015 18:14:54 +0000 Subject: [PATCH] Improve approximation of container creation time. Containers with subcontainers always report creation time to be same as the time of creation of the latest subcontainer. Still not an ideal solution, but accurate for most practical purposes. --- container/raw/handler.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/container/raw/handler.go b/container/raw/handler.go index 3d258e53..836d879a 100644 --- a/container/raw/handler.go +++ b/container/raw/handler.go @@ -177,7 +177,11 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) { now := time.Now() lowestTime := now for _, cgroupPath := range self.cgroupPaths { - // The modified time of the cgroup directory is when the container was created. + // The modified time of the cgroup directory changes whenever a subcontainer is created. + // eg. /docker will have creation time matching the creation of latest docker container. + // Use clone_children as a workaround as it isn't usually modified. It is only likely changed + // immediately after creating a container. + cgroupPath = path.Join(cgroupPath, "cgroup.clone_children") fi, err := os.Stat(cgroupPath) if err == nil && fi.ModTime().Before(lowestTime) { lowestTime = fi.ModTime()