diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 337d07dec7..75fcdc98f2 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -477,7 +477,11 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) ( var sharedDirMounts []Mount var ignoredMounts []Mount for idx, m := range c.mounts { - if isSystemMount(m.Destination) || m.Type != "bind" { + if isSystemMount(m.Destination) && !IsDockerVolume(m.Source) { + continue + } + + if m.Type != "bind" { continue } diff --git a/virtcontainers/mount.go b/virtcontainers/mount.go index 5ffa7c5713..6dc6b62f38 100644 --- a/virtcontainers/mount.go +++ b/virtcontainers/mount.go @@ -326,3 +326,19 @@ func bindUnmountAllRootfs(ctx context.Context, sharedDir string, sandbox *Sandbo } } } + +const ( + dockerVolumePrefix = "/var/lib/docker/volumes" + dockerVolumeSuffix = "_data" +) + +// IsDockerVolume returns true if the given source path is +// a docker volume. +// This uses a very specific path that is used by docker. +func IsDockerVolume(path string) bool { + if strings.HasPrefix(path, dockerVolumePrefix) && filepath.Base(path) == dockerVolumeSuffix { + return true + } + return false +} + diff --git a/virtcontainers/mount_test.go b/virtcontainers/mount_test.go index 820fd7447c..f39fa3c489 100644 --- a/virtcontainers/mount_test.go +++ b/virtcontainers/mount_test.go @@ -282,3 +282,13 @@ func TestIsDeviceMapper(t *testing.T) { t.Fatal() } } + +func TestIsDockerVolume(t *testing.T) { + path := "/var/lib/docker/volumes/00da1347c7cf4f15db35f/_data" + isDockerVolume := IsDockerVolume(path) + assert.True(t, isDockerVolume) + + path = "/var/lib/testdir" + isDockerVolume := IsDockerVolume(path) + assert.False(t, isDockerVolume) +}