Skip to content

Commit 4302ab3

Browse files
fix: handle DOS-style path for Dockerfile in minikube build
1 parent aca5f29 commit 4302ab3

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

cmd/minikube/cmd/image.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/minikube/pkg/minikube/exit"
3131
"k8s.io/minikube/pkg/minikube/image"
3232
"k8s.io/minikube/pkg/minikube/machine"
33+
"k8s.io/minikube/pkg/minikube/out"
3334
"k8s.io/minikube/pkg/minikube/reason"
3435
docker "k8s.io/minikube/third_party/go-dockerclient"
3536
)
@@ -45,16 +46,17 @@ var imageCmd = &cobra.Command{
4546
}
4647

4748
var (
48-
pull bool
49-
imgDaemon bool
50-
imgRemote bool
51-
overwrite bool
52-
tag string
53-
push bool
54-
dockerFile string
55-
buildEnv []string
56-
buildOpt []string
57-
format string
49+
pull bool
50+
imgDaemon bool
51+
imgRemote bool
52+
overwrite bool
53+
tag string
54+
push bool
55+
dockerFile string
56+
buildEnv []string
57+
buildOpt []string
58+
format string
59+
noDosPathConversion bool
5860
)
5961

6062
func saveFile(r io.Reader) (string, error) {
@@ -310,6 +312,12 @@ var buildImageCmd = &cobra.Command{
310312
// Otherwise, assume it's a tar
311313
}
312314
}
315+
if runtime.GOOS == "windows" && strings.Contains(dockerFile, "\\") && !noDosPathConversion {
316+
// if dockerFile is a DOS path, and user did not explicitly forbid this conversion, translate it into UNIX path
317+
// because we are going to build this image in UNIX environment
318+
out.String("minikube detects that you are using DOS-style path %s. Minikube will convert it to UNIX-style by replacing all \\ to /", dockerFile)
319+
dockerFile = strings.ReplaceAll(dockerFile, "\\", "/")
320+
}
313321
if err := machine.BuildImage(img, dockerFile, tag, push, buildEnv, buildOpt, []*config.Profile{profile}, allNodes, nodeName); err != nil {
314322
exit.Error(reason.GuestImageBuild, "Failed to build image", err)
315323
}
@@ -393,6 +401,7 @@ func init() {
393401
buildImageCmd.Flags().StringArrayVar(&buildOpt, "build-opt", nil, "Specify arbitrary flags to pass to the build. (format: key=value)")
394402
buildImageCmd.Flags().StringVarP(&nodeName, "node", "n", "", "The node to build on. Defaults to the primary control plane.")
395403
buildImageCmd.Flags().BoolVarP(&allNodes, "all", "", false, "Build image on all nodes.")
404+
buildImageCmd.Flags().BoolVarP(&noDosPathConversion, "no-dospath-conversion", "", false, "No automatic conversion from DOS-style path to UNIX-style path for Dockerfile")
396405
imageCmd.AddCommand(buildImageCmd)
397406
saveImageCmd.Flags().BoolVar(&imgDaemon, "daemon", false, "Cache image to docker daemon")
398407
saveImageCmd.Flags().BoolVar(&imgRemote, "remote", false, "Cache image to remote registry")

0 commit comments

Comments
 (0)