mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
This commit is contained in:
parent
66b231d598
commit
76d96418b1
4 changed files with 9 additions and 16 deletions
|
@ -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)
|
||||
|
@ -291,7 +287,6 @@ func TestMigratePre17Volumes(t *testing.T) {
|
|||
daemon := &Daemon{
|
||||
root: rootDir,
|
||||
repository: containerRoot,
|
||||
containersReplica: viewDB,
|
||||
volumes: volStore,
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue