From 4908d7f81db91f4a28be152ec0cacb0cf711b403 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 14 Nov 2013 22:52:08 -0800 Subject: [PATCH] Save driver to container and skip incompat containers For people who toggle drivers we want to save the driver used to create a container so that if the driver changes we can skip loading the container and it should not show up in docker ps --- container.go | 1 + runtime.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/container.go b/container.go index 0e54abe52c..ed4e5f4777 100644 --- a/container.go +++ b/container.go @@ -47,6 +47,7 @@ type Container struct { HostnamePath string HostsPath string Name string + Driver string cmd *exec.Cmd stdout *utils.WriteBroadcaster diff --git a/runtime.go b/runtime.go index 48d632b3e8..57e5498ff4 100644 --- a/runtime.go +++ b/runtime.go @@ -262,6 +262,7 @@ func (runtime *Runtime) restore() error { return err } containers := make(map[string]*Container) + currentDriver := runtime.driver.String() for i, v := range dir { id := v.Name() @@ -273,8 +274,14 @@ func (runtime *Runtime) restore() error { utils.Errorf("Failed to load container %v: %v", id, err) continue } - utils.Debugf("Loaded container %v", container.ID) - containers[container.ID] = container + + // Ignore the container if it does not support the current driver being used by the graph + if container.Driver == "" && currentDriver == "aufs" || container.Driver == currentDriver { + utils.Debugf("Loaded container %v", container.ID) + containers[container.ID] = container + } else { + utils.Debugf("Cannot load container %s because it was created with another graph driver.", container.ID) + } } register := func(container *Container) { @@ -445,6 +452,7 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin // FIXME: do we need to store this in the container? SysInitPath: sysInitPath, Name: name, + Driver: runtime.driver.String(), } container.root = runtime.containerRoot(container.ID) // Step 1: create the container directory.