@@ -19,6 +19,7 @@ package compose
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "path"
22
23
"path/filepath"
23
24
"strconv"
24
25
"strings"
@@ -630,6 +631,7 @@ MOUNTS:
630
631
func buildContainerMountOptions (p types.Project , s types.ServiceConfig , img moby.ImageInspect , inherit * moby.Container ) ([]mount.Mount , error ) {
631
632
var mounts = map [string ]mount.Mount {}
632
633
if inherit != nil {
634
+
633
635
for _ , m := range inherit .Mounts {
634
636
if m .Type == "tmpfs" {
635
637
continue
@@ -638,24 +640,20 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
638
640
if m .Type == "volume" {
639
641
src = m .Name
640
642
}
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
+ }
657
655
}
658
- mounts [ k ] = m
656
+
659
657
}
660
658
}
661
659
@@ -801,6 +799,8 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
801
799
802
800
bind , vol , tmpfs := buildMountOptions (volume )
803
801
802
+ volume .Target = path .Clean (volume .Target )
803
+
804
804
return mount.Mount {
805
805
Type : mount .Type (volume .Type ),
806
806
Source : source ,
0 commit comments