docker_cli_exec_test.go 18 KB

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