From 9043d39deaa9b8d6b64efd5b4eb0a2225d91dee2 Mon Sep 17 00:00:00 2001 From: John Stephens Date: Sat, 27 May 2017 12:29:30 -0700 Subject: [PATCH] Fix stack compose bind-mount volumes for Windows For stack compose files, use filepath.IsAbs instead of path.IsAbs, for bind-mounted service volumes, because filepath.IsAbs handles Windows paths, while path.IsAbs does not. Signed-off-by: John Stephens --- cli/compose/loader/loader.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index 0ed8ce87d7..f12a7f0eea 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -3,6 +3,7 @@ package loader import ( "fmt" "path" + "path/filepath" "reflect" "sort" "strings" @@ -371,7 +372,16 @@ func resolveVolumePaths(volumes []types.ServiceVolumeConfig, workingDir string, continue } - volume.Source = absPath(workingDir, expandUser(volume.Source, lookupEnv)) + filePath := expandUser(volume.Source, lookupEnv) + // Check for a Unix absolute path first, to handle a Windows client + // with a Unix daemon. This handles a Windows client connecting to a + // Unix daemon. Note that this is not required for Docker for Windows + // when specifying a local Windows path, because Docker for Windows + // translates the Windows path into a valid path within the VM. + if !path.IsAbs(filePath) { + filePath = absPath(workingDir, filePath) + } + volume.Source = filePath volumes[i] = volume } } @@ -492,11 +502,11 @@ func LoadConfigObjs(source map[string]interface{}, workingDir string) (map[strin return configs, nil } -func absPath(workingDir string, filepath string) string { - if path.IsAbs(filepath) { - return filepath +func absPath(workingDir string, filePath string) string { + if filepath.IsAbs(filePath) { + return filePath } - return path.Join(workingDir, filepath) + return filepath.Join(workingDir, filePath) } func transformMapStringString(data interface{}) (interface{}, error) {