avoid saving container state to disk before daemon.Register
Migrate legacy volumes (Daemon.verifyVolumesInfo) before containers are registered on the Daemon, so state on disk is not overwritten and legacy fields lost during registration. Signed-off-by: Fabio Kung <fabio.kung@gmail.com> Upstream-commit: 76d96418b13080514f3fb861072b06cb91d71cff Component: engine
This commit is contained in:
@ -187,17 +187,16 @@ func (daemon *Daemon) restore() error {
|
||||
delete(containers, id)
|
||||
continue
|
||||
}
|
||||
if err := daemon.Register(c); err != nil {
|
||||
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
|
||||
delete(containers, id)
|
||||
continue
|
||||
}
|
||||
|
||||
// verify that all volumes valid and have been migrated from the pre-1.7 layout
|
||||
if err := daemon.verifyVolumesInfo(c); err != nil {
|
||||
// don't skip the container due to error
|
||||
logrus.Errorf("Failed to verify volumes for container '%s': %v", c.ID, err)
|
||||
}
|
||||
if err := daemon.Register(c); err != nil {
|
||||
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
|
||||
delete(containers, id)
|
||||
continue
|
||||
}
|
||||
|
||||
// The LogConfig.Type is empty if the container was created before docker 1.12 with default log driver.
|
||||
// We should rewrite it to use the daemon defaults.
|
||||
|
||||
@ -274,10 +274,6 @@ func TestMigratePre17Volumes(t *testing.T) {
|
||||
}
|
||||
`)
|
||||
|
||||
viewDB, err := container.NewViewDB()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
volStore, err := store.New(volumeRoot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -289,10 +285,9 @@ func TestMigratePre17Volumes(t *testing.T) {
|
||||
volumedrivers.Register(drv, volume.DefaultDriverName)
|
||||
|
||||
daemon := &Daemon{
|
||||
root: rootDir,
|
||||
repository: containerRoot,
|
||||
containersReplica: viewDB,
|
||||
volumes: volStore,
|
||||
root: rootDir,
|
||||
repository: containerRoot,
|
||||
volumes: volStore,
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600)
|
||||
if err != nil {
|
||||
|
||||
@ -180,7 +180,6 @@ func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error {
|
||||
container.MountPoints[destination] = &m
|
||||
}
|
||||
}
|
||||
return container.CheckpointTo(daemon.containersReplica)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -2684,7 +2684,7 @@ func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) {
|
||||
`)
|
||||
|
||||
configPath := filepath.Join(d.Root, "containers", id, "config.v2.json")
|
||||
err = ioutil.WriteFile(configPath, config, 600)
|
||||
c.Assert(ioutil.WriteFile(configPath, config, 600), checker.IsNil)
|
||||
d.Start(c)
|
||||
|
||||
out, err = d.Cmd("inspect", "--type=container", "--format={{ json .Mounts }}", id)
|
||||
|
||||
Reference in New Issue
Block a user