docker_cli_exec_test.go 18 KB

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