diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 19a2d158cca9..f59d16be62f6 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -15,6 +15,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/api/types/versions" @@ -343,12 +344,26 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con 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 + } + + 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 + // we do not want bind mounts being committed to image configs + binds = append(binds, bind) } }