Skip to content

Commit 4ffc614

Browse files
authored
Merge pull request #45903 from thaJeztah/24.0_backport_fix_volume_npe
[24.0 backport] daemon: daemon.prepareMountPoints(): fix panic if mount is not a volume
2 parents 1d9c861 + d3893b5 commit 4ffc614

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

daemon/mounts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
1818
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
1919
return err
2020
}
21+
if config.Volume == nil {
22+
// FIXME(thaJeztah): should we check for config.Type here as well? (i.e., skip bind-mounts etc)
23+
continue
24+
}
2125
if alive {
2226
log.G(context.TODO()).WithFields(logrus.Fields{
2327
"container": container.ID,

integration/daemon/daemon_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
436436
err = c.VolumeRemove(ctx, v.Name, false)
437437
assert.NilError(t, err)
438438
})
439+
440+
// Make sure that we don't panic if the container has bind-mounts
441+
// (which should not be "restored")
442+
// Regression test for https://github.com/moby/moby/issues/45898
443+
t.Run("container with bind-mounts", func(t *testing.T) {
444+
m := mount.Mount{
445+
Type: mount.TypeBind,
446+
Source: os.TempDir(),
447+
Target: "/foo",
448+
}
449+
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"))
450+
defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
451+
452+
d.Restart(t, "--live-restore", "--iptables=false")
453+
454+
err := c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
455+
assert.NilError(t, err)
456+
})
439457
}
440458

441459
func TestDaemonDefaultBridgeWithFixedCidrButNoBip(t *testing.T) {

0 commit comments

Comments
 (0)