Skip to content

Commit 3903f95

Browse files
committed
resolve device path for local bind mount volumes
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent b764b46 commit 3903f95

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

loader/loader_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,3 +2131,26 @@ services:
21312131
assert.Equal(t, "env-var-web", svc.ContainerName)
21322132
})
21332133
}
2134+
2135+
func TestLoadWithBindMountVolume(t *testing.T) {
2136+
dict := `
2137+
services:
2138+
web:
2139+
image: web
2140+
volumes:
2141+
- data:/data
2142+
volumes:
2143+
data:
2144+
driver: local
2145+
driver_opts:
2146+
type: 'none'
2147+
o: 'bind'
2148+
device: './data'
2149+
`
2150+
configDetails := buildConfigDetails(dict, nil)
2151+
2152+
project, err := Load(configDetails)
2153+
assert.NilError(t, err)
2154+
path := project.Volumes["data"].DriverOpts["device"]
2155+
assert.Check(t, filepath.IsAbs(path))
2156+
}

loader/normalize.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ func normalize(project *types.Project, resolvePaths bool) error {
110110
project.Services[i] = s
111111
}
112112

113+
for name, config := range project.Volumes {
114+
if config.Driver == "local" && config.DriverOpts["o"] == "bind" {
115+
// This is actually a bind mount
116+
config.DriverOpts["device"] = absPath(project.WorkingDir, config.DriverOpts["device"])
117+
project.Volumes[name] = config
118+
}
119+
}
120+
113121
setNameFromKey(project)
114122

115123
return nil

0 commit comments

Comments
 (0)