Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 43655ba

Browse files
authored
Merge pull request #1782 from ndeloof/inherited_volume
fix volume inheritance and conflict with trailing '/'
2 parents f06baee + 726e204 commit 43655ba

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

local/compose/create.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"path"
2223
"path/filepath"
2324
"strconv"
2425
"strings"
@@ -630,6 +631,7 @@ MOUNTS:
630631
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
631632
var mounts = map[string]mount.Mount{}
632633
if inherit != nil {
634+
633635
for _, m := range inherit.Mounts {
634636
if m.Type == "tmpfs" {
635637
continue
@@ -638,24 +640,20 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
638640
if m.Type == "volume" {
639641
src = m.Name
640642
}
641-
mounts[m.Destination] = mount.Mount{
642-
Type: m.Type,
643-
Source: src,
644-
Target: m.Destination,
645-
ReadOnly: !m.RW,
646-
}
647-
}
648-
}
649-
if img.ContainerConfig != nil {
650-
for k := range img.ContainerConfig.Volumes {
651-
m, err := buildMount(p, types.ServiceVolumeConfig{
652-
Type: types.VolumeTypeVolume,
653-
Target: k,
654-
})
655-
if err != nil {
656-
return nil, err
643+
m.Destination = path.Clean(m.Destination)
644+
645+
if img.Config != nil {
646+
if _, ok := img.Config.Volumes[m.Destination]; ok {
647+
// inherit previous container's anonymous volume
648+
mounts[m.Destination] = mount.Mount{
649+
Type: m.Type,
650+
Source: src,
651+
Target: m.Destination,
652+
ReadOnly: !m.RW,
653+
}
654+
}
657655
}
658-
mounts[k] = m
656+
659657
}
660658
}
661659

@@ -801,6 +799,8 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
801799

802800
bind, vol, tmpfs := buildMountOptions(volume)
803801

802+
volume.Target = path.Clean(volume.Target)
803+
804804
return mount.Mount{
805805
Type: mount.Type(volume.Type),
806806
Source: source,

0 commit comments

Comments
 (0)