mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
fix volume inheritance and conflict with trailing '/'
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
f06baeef20
commit
726e204099
@ -19,6 +19,7 @@ package compose
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -630,6 +631,7 @@ MOUNTS:
|
|||||||
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
|
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
|
||||||
var mounts = map[string]mount.Mount{}
|
var mounts = map[string]mount.Mount{}
|
||||||
if inherit != nil {
|
if inherit != nil {
|
||||||
|
|
||||||
for _, m := range inherit.Mounts {
|
for _, m := range inherit.Mounts {
|
||||||
if m.Type == "tmpfs" {
|
if m.Type == "tmpfs" {
|
||||||
continue
|
continue
|
||||||
@ -638,24 +640,20 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
|
|||||||
if m.Type == "volume" {
|
if m.Type == "volume" {
|
||||||
src = m.Name
|
src = m.Name
|
||||||
}
|
}
|
||||||
mounts[m.Destination] = mount.Mount{
|
m.Destination = path.Clean(m.Destination)
|
||||||
Type: m.Type,
|
|
||||||
Source: src,
|
if img.Config != nil {
|
||||||
Target: m.Destination,
|
if _, ok := img.Config.Volumes[m.Destination]; ok {
|
||||||
ReadOnly: !m.RW,
|
// inherit previous container's anonymous volume
|
||||||
|
mounts[m.Destination] = mount.Mount{
|
||||||
|
Type: m.Type,
|
||||||
|
Source: src,
|
||||||
|
Target: m.Destination,
|
||||||
|
ReadOnly: !m.RW,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if img.ContainerConfig != nil {
|
|
||||||
for k := range img.ContainerConfig.Volumes {
|
|
||||||
m, err := buildMount(p, types.ServiceVolumeConfig{
|
|
||||||
Type: types.VolumeTypeVolume,
|
|
||||||
Target: k,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
mounts[k] = m
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,6 +799,8 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
|
|||||||
|
|
||||||
bind, vol, tmpfs := buildMountOptions(volume)
|
bind, vol, tmpfs := buildMountOptions(volume)
|
||||||
|
|
||||||
|
volume.Target = path.Clean(volume.Target)
|
||||||
|
|
||||||
return mount.Mount{
|
return mount.Mount{
|
||||||
Type: mount.Type(volume.Type),
|
Type: mount.Type(volume.Type),
|
||||||
Source: source,
|
Source: source,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user