From e07ce9741fb117cef8eadd0cacfe7844772a7fb8 Mon Sep 17 00:00:00 2001 From: Matthew Wo <9029537@gmail.com> Date: Sat, 4 Aug 2018 14:57:02 -0700 Subject: [PATCH 1/3] Support for relative path in bind mounts Signed-off-by: Matthew Wo <9029537@gmail.com> --- cli/command/container/opts.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 97906b672252..b9aceeb2cf3b 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -14,6 +14,7 @@ import ( "github.com/docker/cli/cli/compose/loader" "github.com/docker/cli/opts" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/pkg/signal" @@ -335,12 +336,23 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err for bind := range copts.volumes.GetMap() { parsed, _ := loader.ParseVolume(bind) if parsed.Source != "" { - // after creating the bind mount we want to delete it from the copts.volumes values because - // we do not want bind mounts being committed to image configs - binds = append(binds, bind) // We should delete from the map (`volumes`) here, as deleting from copts.volumes will not work if // there are duplicates entries. delete(volumes, bind) + + if parsed.Type == string(mount.TypeBind) { + // Resolve relative path of source volume if needed + resolved, err := resolveLocalPath(parsed.Source) + if err != nil { + return nil, err + } + // use the resolved file path + bind = resolved + ":" + parsed.Target + } + + // after creating the bind mount we want to delete it from the copts.volumes values because + // we do not want bind mounts being committed to image configs + binds = append(binds, bind) } } From 026fef4048eeeea87ab6655651ba4e0e89096973 Mon Sep 17 00:00:00 2001 From: Matthew Wo <9029537@gmail.com> Date: Sun, 5 Aug 2018 09:21:00 -0700 Subject: [PATCH 2/3] fix no readonly and consistency flags in bind mount Signed-off-by: Matthew Wo <9029537@gmail.com> --- cli/command/container/opts.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index b9aceeb2cf3b..f59053ff7bc9 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -348,6 +348,12 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err } // use the resolved file path bind = resolved + ":" + parsed.Target + if parsed.ReadOnly { + bind += ":ro" + } + if parsed.Consistency != "" { + bind += ":" + parsed.Consistency + } } // after creating the bind mount we want to delete it from the copts.volumes values because From 0e347a27910a515074db9935e44edf1eb10cce6f Mon Sep 17 00:00:00 2001 From: Matthew Wo <9029537@gmail.com> Date: Thu, 3 Oct 2019 16:45:24 +0800 Subject: [PATCH 3/3] fix rw / ro flag issue --- cli/command/container/opts.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 71ae8b16537a..f59d16be62f6 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -354,14 +354,11 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con if err != nil { return nil, err } - // use the resolved file path - bind = resolved + ":" + parsed.Target - if parsed.ReadOnly { - bind += ":ro" - } - if parsed.Consistency != "" { - bind += ":" + parsed.Consistency - } + + parts := strings.Split(bind, ":") + parts[0] = resolved + + bind = strings.Join(parts[:], ":") } // after creating the bind mount we want to delete it from the copts.volumes values because