Pārlūkot izejas kodu

Windows: Don't set PATH/TERM on exec

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 8 gadi atpakaļ
vecāks
revīzija
e880bbc48b
2 mainītis faili ar 21 papildinājumiem un 5 dzēšanām
  1. 10 5
      daemon/exec.go
  2. 11 0
      integration-cli/docker_cli_exec_test.go

+ 10 - 5
daemon/exec.go

@@ -3,6 +3,7 @@ package daemon
 import (
 import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
+	"runtime"
 	"strings"
 	"strings"
 	"time"
 	"time"
 
 
@@ -123,11 +124,15 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
 	execConfig.Tty = config.Tty
 	execConfig.Tty = config.Tty
 	execConfig.Privileged = config.Privileged
 	execConfig.Privileged = config.Privileged
 	execConfig.User = config.User
 	execConfig.User = config.User
-	execConfig.Env = []string{
-		"PATH=" + system.DefaultPathEnv,
-	}
-	if config.Tty {
-		execConfig.Env = append(execConfig.Env, "TERM=xterm")
+
+	// On Windows, don't default the path, let the platform do it. Also TERM isn't meaningful
+	if runtime.GOOS != "windows" {
+		execConfig.Env = []string{
+			"PATH=" + system.DefaultPathEnv,
+		}
+		if config.Tty {
+			execConfig.Env = append(execConfig.Env, "TERM=xterm")
+		}
 	}
 	}
 	execConfig.Env = utils.ReplaceOrAppendEnvValues(execConfig.Env, container.Config.Env)
 	execConfig.Env = utils.ReplaceOrAppendEnvValues(execConfig.Env, container.Config.Env)
 	if len(execConfig.User) == 0 {
 	if len(execConfig.User) == 0 {

+ 11 - 0
integration-cli/docker_cli_exec_test.go

@@ -509,3 +509,14 @@ func (s *DockerSuite) TestExecStartFails(c *check.C) {
 	c.Assert(err, checker.NotNil, check.Commentf(out))
 	c.Assert(err, checker.NotNil, check.Commentf(out))
 	c.Assert(out, checker.Contains, "executable file not found")
 	c.Assert(out, checker.Contains, "executable file not found")
 }
 }
+
+// Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297
+func (s *DockerSuite) TestExecWindowsPathNotWiped(c *check.C) {
+	testRequires(c, DaemonIsWindows)
+	out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60")
+	c.Assert(waitRun(strings.TrimSpace(out)), check.IsNil)
+
+	out, _ = dockerCmd(c, "exec", "testing", "powershell", "write-host", "$env:PATH")
+	out = strings.ToLower(strings.Trim(out, "\r\n"))
+	c.Assert(out, checker.Contains, `windowspowershell\v1.0`)
+}