docker_cli_exec_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. package main
  2. import (
  3. "bufio"
  4. "context"
  5. "fmt"
  6. "os"
  7. "os/exec"
  8. "reflect"
  9. "runtime"
  10. "sort"
  11. "strings"
  12. "sync"
  13. "testing"
  14. "time"
  15. "github.com/docker/docker/client"
  16. "github.com/docker/docker/integration-cli/cli"
  17. "github.com/docker/docker/integration-cli/cli/build"
  18. "github.com/docker/docker/testutil"
  19. "gotest.tools/v3/assert"
  20. is "gotest.tools/v3/assert/cmp"
  21. "gotest.tools/v3/icmd"
  22. )
  23. type DockerCLIExecSuite struct {
  24. ds *DockerSuite
  25. }
  26. func (s *DockerCLIExecSuite) TearDownTest(ctx context.Context, c *testing.T) {
  27. s.ds.TearDownTest(ctx, c)
  28. }
  29. func (s *DockerCLIExecSuite) OnTimeout(c *testing.T) {
  30. s.ds.OnTimeout(c)
  31. }
  32. func (s *DockerCLIExecSuite) TestExec(c *testing.T) {
  33. testRequires(c, DaemonIsLinux)
  34. out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
  35. assert.NilError(c, waitRun(strings.TrimSpace(out)))
  36. out, _ = dockerCmd(c, "exec", "testing", "cat", "/tmp/file")
  37. assert.Equal(c, strings.Trim(out, "\r\n"), "test")
  38. }
  39. func (s *DockerCLIExecSuite) TestExecInteractive(c *testing.T) {
  40. testRequires(c, DaemonIsLinux)
  41. dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
  42. execCmd := exec.Command(dockerBinary, "exec", "-i", "testing", "sh")
  43. stdin, err := execCmd.StdinPipe()
  44. assert.NilError(c, err)
  45. stdout, err := execCmd.StdoutPipe()
  46. assert.NilError(c, err)
  47. err = execCmd.Start()
  48. assert.NilError(c, err)
  49. _, err = stdin.Write([]byte("cat /tmp/file\n"))
  50. assert.NilError(c, err)
  51. r := bufio.NewReader(stdout)
  52. line, err := r.ReadString('\n')
  53. assert.NilError(c, err)
  54. line = strings.TrimSpace(line)
  55. assert.Equal(c, line, "test")
  56. err = stdin.Close()
  57. assert.NilError(c, err)
  58. errChan := make(chan error, 1)
  59. go func() {
  60. errChan <- execCmd.Wait()
  61. close(errChan)
  62. }()
  63. select {
  64. case err := <-errChan:
  65. assert.NilError(c, err)
  66. case <-time.After(1 * time.Second):
  67. c.Fatal("docker exec failed to exit on stdin close")
  68. }
  69. }
  70. func (s *DockerCLIExecSuite) TestExecAfterContainerRestart(c *testing.T) {
  71. out := runSleepingContainer(c)
  72. cleanedContainerID := strings.TrimSpace(out)
  73. assert.NilError(c, waitRun(cleanedContainerID))
  74. dockerCmd(c, "restart", cleanedContainerID)
  75. assert.NilError(c, waitRun(cleanedContainerID))
  76. out, _ = dockerCmd(c, "exec", cleanedContainerID, "echo", "hello")
  77. assert.Equal(c, strings.TrimSpace(out), "hello")
  78. }
  79. func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *testing.T) {
  80. ctx := testutil.GetContext(c)
  81. // TODO Windows CI: DockerDaemonSuite doesn't run on Windows, and requires a little work to get this ported.
  82. s.d.StartWithBusybox(ctx, c)
  83. out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top")
  84. assert.NilError(c, err, "Could not run top: %s", out)
  85. s.d.Restart(c)
  86. out, err = s.d.Cmd("start", "top")
  87. assert.NilError(c, err, "Could not start top after daemon restart: %s", out)
  88. out, err = s.d.Cmd("exec", "top", "echo", "hello")
  89. assert.NilError(c, err, "Could not exec on container top: %s", out)
  90. assert.Equal(c, strings.TrimSpace(out), "hello")
  91. }
  92. // Regression test for #9155, #9044
  93. func (s *DockerCLIExecSuite) TestExecEnv(c *testing.T) {
  94. // TODO Windows CI: This one is interesting and may just end up being a feature
  95. // difference between Windows and Linux. On Windows, the environment is passed
  96. // into the process that is launched, not into the machine environment. Hence
  97. // a subsequent exec will not have LALA set/
  98. testRequires(c, DaemonIsLinux)
  99. runSleepingContainer(c, "-e", "LALA=value1", "-e", "LALA=value2", "-d", "--name", "testing")
  100. assert.NilError(c, waitRun("testing"))
  101. out, _ := dockerCmd(c, "exec", "testing", "env")
  102. assert.Check(c, !strings.Contains(out, "LALA=value1"))
  103. assert.Check(c, strings.Contains(out, "LALA=value2"))
  104. assert.Check(c, strings.Contains(out, "HOME=/root"))
  105. }
  106. func (s *DockerCLIExecSuite) TestExecSetEnv(c *testing.T) {
  107. testRequires(c, DaemonIsLinux)
  108. runSleepingContainer(c, "-e", "HOME=/root", "-d", "--name", "testing")
  109. assert.NilError(c, waitRun("testing"))
  110. out, _ := dockerCmd(c, "exec", "-e", "HOME=/another", "-e", "ABC=xyz", "testing", "env")
  111. assert.Check(c, !strings.Contains(out, "HOME=/root"))
  112. assert.Check(c, strings.Contains(out, "HOME=/another"))
  113. assert.Check(c, strings.Contains(out, "ABC=xyz"))
  114. }
  115. func (s *DockerCLIExecSuite) TestExecExitStatus(c *testing.T) {
  116. runSleepingContainer(c, "-d", "--name", "top")
  117. result := icmd.RunCommand(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
  118. result.Assert(c, icmd.Expected{ExitCode: 23, Error: "exit status 23"})
  119. }
  120. func (s *DockerCLIExecSuite) TestExecPausedContainer(c *testing.T) {
  121. testRequires(c, IsPausable)
  122. out := runSleepingContainer(c, "-d", "--name", "testing")
  123. ContainerID := strings.TrimSpace(out)
  124. dockerCmd(c, "pause", "testing")
  125. out, _, err := dockerCmdWithError("exec", ContainerID, "echo", "hello")
  126. assert.ErrorContains(c, err, "", "container should fail to exec new command if it is paused")
  127. expected := ContainerID + " is paused, unpause the container before exec"
  128. assert.Assert(c, is.Contains(out, expected), "container should not exec new command if it is paused")
  129. }
  130. // regression test for #9476
  131. func (s *DockerCLIExecSuite) TestExecTTYCloseStdin(c *testing.T) {
  132. // TODO Windows CI: This requires some work to port to Windows.
  133. testRequires(c, DaemonIsLinux)
  134. dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
  135. cmd := exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat")
  136. stdinRw, err := cmd.StdinPipe()
  137. assert.NilError(c, err)
  138. stdinRw.Write([]byte("test"))
  139. stdinRw.Close()
  140. out, _, err := runCommandWithOutput(cmd)
  141. assert.NilError(c, err, out)
  142. out, _ = dockerCmd(c, "top", "exec_tty_stdin")
  143. outArr := strings.Split(out, "\n")
  144. assert.Assert(c, len(outArr) <= 3, "exec process left running")
  145. assert.Assert(c, !strings.Contains(out, "nsenter-exec"))
  146. }
  147. func (s *DockerCLIExecSuite) TestExecTTYWithoutStdin(c *testing.T) {
  148. out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
  149. id := strings.TrimSpace(out)
  150. assert.NilError(c, waitRun(id))
  151. errChan := make(chan error, 1)
  152. go func() {
  153. defer close(errChan)
  154. cmd := exec.Command(dockerBinary, "exec", "-ti", id, "true")
  155. if _, err := cmd.StdinPipe(); err != nil {
  156. errChan <- err
  157. return
  158. }
  159. expected := "the input device is not a TTY"
  160. if runtime.GOOS == "windows" {
  161. expected += ". If you are using mintty, try prefixing the command with 'winpty'"
  162. }
  163. if out, _, err := runCommandWithOutput(cmd); err == nil {
  164. errChan <- fmt.Errorf("exec should have failed")
  165. return
  166. } else if !strings.Contains(out, expected) {
  167. errChan <- fmt.Errorf("exec failed with error %q: expected %q", out, expected)
  168. return
  169. }
  170. }()
  171. select {
  172. case err := <-errChan:
  173. assert.NilError(c, err)
  174. case <-time.After(3 * time.Second):
  175. c.Fatal("exec is running but should have failed")
  176. }
  177. }
  178. // FIXME(vdemeester) this should be a unit tests on cli/command/container package
  179. func (s *DockerCLIExecSuite) TestExecParseError(c *testing.T) {
  180. // TODO Windows CI: Requires some extra work. Consider copying the
  181. // runSleepingContainer helper to have an exec version.
  182. testRequires(c, DaemonIsLinux)
  183. dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
  184. // Test normal (non-detached) case first
  185. icmd.RunCommand(dockerBinary, "exec", "top").Assert(c, icmd.Expected{
  186. ExitCode: 1,
  187. Error: "exit status 1",
  188. Err: "See 'docker exec --help'",
  189. })
  190. }
  191. func (s *DockerCLIExecSuite) TestExecStopNotHanging(c *testing.T) {
  192. // TODO Windows CI: Requires some extra work. Consider copying the
  193. // runSleepingContainer helper to have an exec version.
  194. testRequires(c, DaemonIsLinux)
  195. dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
  196. result := icmd.StartCmd(icmd.Command(dockerBinary, "exec", "testing", "top"))
  197. result.Assert(c, icmd.Success)
  198. go icmd.WaitOnCmd(0, result)
  199. type dstop struct {
  200. out string
  201. err error
  202. }
  203. ch := make(chan dstop, 1)
  204. go func() {
  205. result := icmd.RunCommand(dockerBinary, "stop", "testing")
  206. ch <- dstop{result.Combined(), result.Error}
  207. close(ch)
  208. }()
  209. select {
  210. case <-time.After(3 * time.Second):
  211. c.Fatal("Container stop timed out")
  212. case s := <-ch:
  213. assert.NilError(c, s.err)
  214. }
  215. }
  216. func (s *DockerCLIExecSuite) TestExecCgroup(c *testing.T) {
  217. // Not applicable on Windows - using Linux specific functionality
  218. testRequires(c, NotUserNamespace)
  219. testRequires(c, DaemonIsLinux)
  220. dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
  221. out, _ := dockerCmd(c, "exec", "testing", "cat", "/proc/1/cgroup")
  222. containerCgroups := sort.StringSlice(strings.Split(out, "\n"))
  223. var wg sync.WaitGroup
  224. var mu sync.Mutex
  225. var execCgroups []sort.StringSlice
  226. errChan := make(chan error, 5)
  227. // exec a few times concurrently to get consistent failure
  228. for i := 0; i < 5; i++ {
  229. wg.Add(1)
  230. go func() {
  231. defer wg.Done()
  232. out, _, err := dockerCmdWithError("exec", "testing", "cat", "/proc/self/cgroup")
  233. if err != nil {
  234. errChan <- err
  235. return
  236. }
  237. cg := sort.StringSlice(strings.Split(out, "\n"))
  238. mu.Lock()
  239. execCgroups = append(execCgroups, cg)
  240. mu.Unlock()
  241. }()
  242. }
  243. wg.Wait()
  244. close(errChan)
  245. for err := range errChan {
  246. assert.NilError(c, err)
  247. }
  248. for _, cg := range execCgroups {
  249. if !reflect.DeepEqual(cg, containerCgroups) {
  250. fmt.Println("exec cgroups:")
  251. for _, name := range cg {
  252. fmt.Printf(" %s\n", name)
  253. }
  254. fmt.Println("container cgroups:")
  255. for _, name := range containerCgroups {
  256. fmt.Printf(" %s\n", name)
  257. }
  258. c.Fatal("cgroups mismatched")
  259. }
  260. }
  261. }
  262. func (s *DockerCLIExecSuite) TestExecInspectID(c *testing.T) {
  263. out := runSleepingContainer(c, "-d")
  264. id := strings.TrimSuffix(out, "\n")
  265. out = inspectField(c, id, "ExecIDs")
  266. assert.Equal(c, out, "[]", "ExecIDs should be empty, got: %s", out)
  267. // Start an exec, have it block waiting so we can do some checking
  268. cmd := exec.Command(dockerBinary, "exec", id, "sh", "-c",
  269. "while ! test -e /execid1; do sleep 1; done")
  270. err := cmd.Start()
  271. assert.NilError(c, err, "failed to start the exec cmd")
  272. // Give the exec 10 chances/seconds to start then give up and stop the test
  273. tries := 10
  274. for i := 0; i < tries; i++ {
  275. // Since its still running we should see exec as part of the container
  276. out = strings.TrimSpace(inspectField(c, id, "ExecIDs"))
  277. if out != "[]" && out != "<no value>" {
  278. break
  279. }
  280. assert.Check(c, i+1 != tries, "ExecIDs still empty after 10 second")
  281. time.Sleep(1 * time.Second)
  282. }
  283. // Save execID for later
  284. execID, err := inspectFilter(id, "index .ExecIDs 0")
  285. assert.NilError(c, err, "failed to get the exec id")
  286. // End the exec by creating the missing file
  287. err = exec.Command(dockerBinary, "exec", id, "sh", "-c", "touch /execid1").Run()
  288. assert.NilError(c, err, "failed to run the 2nd exec cmd")
  289. // Wait for 1st exec to complete
  290. cmd.Wait()
  291. // Give the exec 10 chances/seconds to stop then give up and stop the test
  292. for i := 0; i < tries; i++ {
  293. // Since its still running we should see exec as part of the container
  294. out = strings.TrimSpace(inspectField(c, id, "ExecIDs"))
  295. if out == "[]" {
  296. break
  297. }
  298. assert.Check(c, i+1 != tries, "ExecIDs still empty after 10 second")
  299. time.Sleep(1 * time.Second)
  300. }
  301. // But we should still be able to query the execID
  302. apiClient, err := client.NewClientWithOpts(client.FromEnv)
  303. assert.NilError(c, err)
  304. defer apiClient.Close()
  305. _, err = apiClient.ContainerExecInspect(testutil.GetContext(c), execID)
  306. assert.NilError(c, err)
  307. // Now delete the container and then an 'inspect' on the exec should
  308. // result in a 404 (not 'container not running')
  309. out, ec := dockerCmd(c, "rm", "-f", id)
  310. assert.Equal(c, ec, 0, "error removing container: %s", out)
  311. _, err = apiClient.ContainerExecInspect(testutil.GetContext(c), execID)
  312. assert.ErrorContains(c, err, "No such exec instance")
  313. }
  314. func (s *DockerCLIExecSuite) TestLinksPingLinkedContainersOnRename(c *testing.T) {
  315. // Problematic on Windows as Windows does not support links
  316. testRequires(c, DaemonIsLinux)
  317. var out string
  318. out, _ = dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
  319. idA := strings.TrimSpace(out)
  320. assert.Assert(c, idA != "", "%s, id should not be nil", out)
  321. out, _ = dockerCmd(c, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "top")
  322. idB := strings.TrimSpace(out)
  323. assert.Assert(c, idB != "", "%s, id should not be nil", out)
  324. dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
  325. dockerCmd(c, "rename", "container1", "container_new")
  326. dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
  327. }
  328. func (s *DockerCLIExecSuite) TestRunMutableNetworkFiles(c *testing.T) {
  329. // Not applicable on Windows to Windows CI.
  330. testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux)
  331. for _, fn := range []string{"resolv.conf", "hosts"} {
  332. containers := cli.DockerCmd(c, "ps", "-q", "-a").Combined()
  333. if containers != "" {
  334. cli.DockerCmd(c, append([]string{"rm", "-fv"}, strings.Split(strings.TrimSpace(containers), "\n")...)...)
  335. }
  336. content := runCommandAndReadContainerFile(c, fn, dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn))
  337. assert.Equal(c, strings.TrimSpace(string(content)), "success", "Content was not what was modified in the container", string(content))
  338. out, _ := dockerCmd(c, "run", "-d", "--name", "c2", "busybox", "top")
  339. contID := strings.TrimSpace(out)
  340. netFilePath := containerStorageFile(contID, fn)
  341. f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0o644)
  342. assert.NilError(c, err)
  343. if _, err := f.Seek(0, 0); err != nil {
  344. f.Close()
  345. c.Fatal(err)
  346. }
  347. if err := f.Truncate(0); err != nil {
  348. f.Close()
  349. c.Fatal(err)
  350. }
  351. if _, err := f.Write([]byte("success2\n")); err != nil {
  352. f.Close()
  353. c.Fatal(err)
  354. }
  355. f.Close()
  356. res, _ := dockerCmd(c, "exec", contID, "cat", "/etc/"+fn)
  357. assert.Equal(c, res, "success2\n")
  358. }
  359. }
  360. func (s *DockerCLIExecSuite) TestExecWithUser(c *testing.T) {
  361. // TODO Windows CI: This may be fixable in the future once Windows
  362. // supports users
  363. testRequires(c, DaemonIsLinux)
  364. dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
  365. out, _ := dockerCmd(c, "exec", "-u", "1", "parent", "id")
  366. assert.Assert(c, strings.Contains(out, "uid=1(daemon) gid=1(daemon)"))
  367. out, _ = dockerCmd(c, "exec", "-u", "root", "parent", "id")
  368. assert.Assert(c, strings.Contains(out, "uid=0(root) gid=0(root)"), "exec with user by id expected daemon user got %s", out)
  369. }
  370. func (s *DockerCLIExecSuite) TestExecWithPrivileged(c *testing.T) {
  371. // Not applicable on Windows
  372. testRequires(c, DaemonIsLinux, NotUserNamespace)
  373. // Start main loop which attempts mknod repeatedly
  374. dockerCmd(c, "run", "-d", "--name", "parent", "--cap-drop=ALL", "busybox", "sh", "-c", `while (true); do if [ -e /exec_priv ]; then cat /exec_priv && mknod /tmp/sda b 8 0 && echo "Success"; else echo "Privileged exec has not run yet"; fi; usleep 10000; done`)
  375. // Check exec mknod doesn't work
  376. icmd.RunCommand(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdb b 8 16").Assert(c, icmd.Expected{
  377. ExitCode: 1,
  378. Err: "Operation not permitted",
  379. })
  380. // Check exec mknod does work with --privileged
  381. result := icmd.RunCommand(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", `echo "Running exec --privileged" > /exec_priv && mknod /tmp/sdb b 8 16 && usleep 50000 && echo "Finished exec --privileged" > /exec_priv && echo ok`)
  382. result.Assert(c, icmd.Success)
  383. actual := strings.TrimSpace(result.Combined())
  384. assert.Equal(c, actual, "ok", "exec mknod in --cap-drop=ALL container with --privileged failed, output: %q", result.Combined())
  385. // Check subsequent unprivileged exec cannot mknod
  386. icmd.RunCommand(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdc b 8 32").Assert(c, icmd.Expected{
  387. ExitCode: 1,
  388. Err: "Operation not permitted",
  389. })
  390. // Confirm at no point was mknod allowed
  391. result = icmd.RunCommand(dockerBinary, "logs", "parent")
  392. result.Assert(c, icmd.Success)
  393. assert.Assert(c, !strings.Contains(result.Combined(), "Success"))
  394. }
  395. func (s *DockerCLIExecSuite) TestExecWithImageUser(c *testing.T) {
  396. // Not applicable on Windows
  397. testRequires(c, DaemonIsLinux)
  398. name := "testbuilduser"
  399. buildImageSuccessfully(c, name, build.WithDockerfile(`FROM busybox
  400. RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
  401. USER dockerio`))
  402. dockerCmd(c, "run", "-d", "--name", "dockerioexec", name, "top")
  403. out, _ := dockerCmd(c, "exec", "dockerioexec", "whoami")
  404. assert.Assert(c, strings.Contains(out, "dockerio"), "exec with user by id expected dockerio user got %s", out)
  405. }
  406. func (s *DockerCLIExecSuite) TestExecOnReadonlyContainer(c *testing.T) {
  407. // Windows does not support read-only
  408. // --read-only + userns has remount issues
  409. testRequires(c, DaemonIsLinux, NotUserNamespace)
  410. dockerCmd(c, "run", "-d", "--read-only", "--name", "parent", "busybox", "top")
  411. dockerCmd(c, "exec", "parent", "true")
  412. }
  413. func (s *DockerCLIExecSuite) TestExecUlimits(c *testing.T) {
  414. testRequires(c, DaemonIsLinux)
  415. name := "testexeculimits"
  416. runSleepingContainer(c, "-d", "--ulimit", "nofile=511:511", "--name", name)
  417. assert.NilError(c, waitRun(name))
  418. out, _, err := dockerCmdWithError("exec", name, "sh", "-c", "ulimit -n")
  419. assert.NilError(c, err)
  420. assert.Equal(c, strings.TrimSpace(out), "511")
  421. }
  422. // #15750
  423. func (s *DockerCLIExecSuite) TestExecStartFails(c *testing.T) {
  424. name := "exec-15750"
  425. runSleepingContainer(c, "-d", "--name", name)
  426. assert.NilError(c, waitRun(name))
  427. out, _, err := dockerCmdWithError("exec", name, "no-such-cmd")
  428. assert.ErrorContains(c, err, "", out)
  429. expectedMsg := "executable file not found"
  430. if DaemonIsWindows() {
  431. expectedMsg = "The system cannot find the file specified"
  432. }
  433. assert.Assert(c, is.Contains(out, expectedMsg))
  434. }
  435. // Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297
  436. func (s *DockerCLIExecSuite) TestExecWindowsPathNotWiped(c *testing.T) {
  437. testRequires(c, DaemonIsWindows)
  438. out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60")
  439. assert.NilError(c, waitRun(strings.TrimSpace(out)))
  440. out, _ = dockerCmd(c, "exec", "testing", "powershell", "write-host", "$env:PATH")
  441. out = strings.ToLower(strings.Trim(out, "\r\n"))
  442. assert.Assert(c, strings.Contains(out, `windowspowershell\v1.0`))
  443. }
  444. func (s *DockerCLIExecSuite) TestExecEnvLinksHost(c *testing.T) {
  445. testRequires(c, DaemonIsLinux)
  446. runSleepingContainer(c, "-d", "--name", "foo")
  447. runSleepingContainer(c, "-d", "--link", "foo:db", "--hostname", "myhost", "--name", "bar")
  448. out, _ := dockerCmd(c, "exec", "bar", "env")
  449. assert.Check(c, is.Contains(out, "HOSTNAME=myhost"))
  450. assert.Check(c, is.Contains(out, "DB_NAME=/bar/db"))
  451. }