docker_cli_exec_test.go 18 KB

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