docker_cli_exec_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. // +build !test_no_exec
  2. package main
  3. import (
  4. "bufio"
  5. "fmt"
  6. "os"
  7. "os/exec"
  8. "path/filepath"
  9. "reflect"
  10. "sort"
  11. "strings"
  12. "sync"
  13. "time"
  14. "github.com/go-check/check"
  15. )
  16. func (s *DockerSuite) TestExec(c *check.C) {
  17. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
  18. if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
  19. c.Fatal(out, err)
  20. }
  21. execCmd := exec.Command(dockerBinary, "exec", "testing", "cat", "/tmp/file")
  22. out, _, err := runCommandWithOutput(execCmd)
  23. if err != nil {
  24. c.Fatal(out, err)
  25. }
  26. out = strings.Trim(out, "\r\n")
  27. if expected := "test"; out != expected {
  28. c.Errorf("container exec should've printed %q but printed %q", expected, out)
  29. }
  30. }
  31. func (s *DockerSuite) TestExecInteractive(c *check.C) {
  32. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
  33. if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
  34. c.Fatal(out, err)
  35. }
  36. execCmd := exec.Command(dockerBinary, "exec", "-i", "testing", "sh")
  37. stdin, err := execCmd.StdinPipe()
  38. if err != nil {
  39. c.Fatal(err)
  40. }
  41. stdout, err := execCmd.StdoutPipe()
  42. if err != nil {
  43. c.Fatal(err)
  44. }
  45. if err := execCmd.Start(); err != nil {
  46. c.Fatal(err)
  47. }
  48. if _, err := stdin.Write([]byte("cat /tmp/file\n")); err != nil {
  49. c.Fatal(err)
  50. }
  51. r := bufio.NewReader(stdout)
  52. line, err := r.ReadString('\n')
  53. if err != nil {
  54. c.Fatal(err)
  55. }
  56. line = strings.TrimSpace(line)
  57. if line != "test" {
  58. c.Fatalf("Output should be 'test', got '%q'", line)
  59. }
  60. if err := stdin.Close(); err != nil {
  61. c.Fatal(err)
  62. }
  63. errChan := make(chan error)
  64. go func() {
  65. errChan <- execCmd.Wait()
  66. close(errChan)
  67. }()
  68. select {
  69. case err := <-errChan:
  70. c.Assert(err, check.IsNil)
  71. case <-time.After(1 * time.Second):
  72. c.Fatal("docker exec failed to exit on stdin close")
  73. }
  74. }
  75. func (s *DockerSuite) TestExecAfterContainerRestart(c *check.C) {
  76. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  77. out, _, err := runCommandWithOutput(runCmd)
  78. if err != nil {
  79. c.Fatal(out, err)
  80. }
  81. cleanedContainerID := strings.TrimSpace(out)
  82. runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID)
  83. if out, _, err = runCommandWithOutput(runCmd); err != nil {
  84. c.Fatal(out, err)
  85. }
  86. runCmd = exec.Command(dockerBinary, "exec", cleanedContainerID, "echo", "hello")
  87. out, _, err = runCommandWithOutput(runCmd)
  88. if err != nil {
  89. c.Fatal(out, err)
  90. }
  91. outStr := strings.TrimSpace(out)
  92. if outStr != "hello" {
  93. c.Errorf("container should've printed hello, instead printed %q", outStr)
  94. }
  95. }
  96. func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
  97. testRequires(c, SameHostDaemon)
  98. if err := s.d.StartWithBusybox(); err != nil {
  99. c.Fatalf("Could not start daemon with busybox: %v", err)
  100. }
  101. if out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top"); err != nil {
  102. c.Fatalf("Could not run top: err=%v\n%s", err, out)
  103. }
  104. if err := s.d.Restart(); err != nil {
  105. c.Fatalf("Could not restart daemon: %v", err)
  106. }
  107. if out, err := s.d.Cmd("start", "top"); err != nil {
  108. c.Fatalf("Could not start top after daemon restart: err=%v\n%s", err, out)
  109. }
  110. out, err := s.d.Cmd("exec", "top", "echo", "hello")
  111. if err != nil {
  112. c.Fatalf("Could not exec on container top: err=%v\n%s", err, out)
  113. }
  114. outStr := strings.TrimSpace(string(out))
  115. if outStr != "hello" {
  116. c.Errorf("container should've printed hello, instead printed %q", outStr)
  117. }
  118. }
  119. // Regression test for #9155, #9044
  120. func (s *DockerSuite) TestExecEnv(c *check.C) {
  121. runCmd := exec.Command(dockerBinary, "run",
  122. "-e", "LALA=value1",
  123. "-e", "LALA=value2",
  124. "-d", "--name", "testing", "busybox", "top")
  125. if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
  126. c.Fatal(out, err)
  127. }
  128. execCmd := exec.Command(dockerBinary, "exec", "testing", "env")
  129. out, _, err := runCommandWithOutput(execCmd)
  130. if err != nil {
  131. c.Fatal(out, err)
  132. }
  133. if strings.Contains(out, "LALA=value1") ||
  134. !strings.Contains(out, "LALA=value2") ||
  135. !strings.Contains(out, "HOME=/root") {
  136. c.Errorf("exec env(%q), expect %q, %q", out, "LALA=value2", "HOME=/root")
  137. }
  138. }
  139. func (s *DockerSuite) TestExecExitStatus(c *check.C) {
  140. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
  141. if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
  142. c.Fatal(out, err)
  143. }
  144. // Test normal (non-detached) case first
  145. cmd := exec.Command(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
  146. ec, _ := runCommand(cmd)
  147. if ec != 23 {
  148. c.Fatalf("Should have had an ExitCode of 23, not: %d", ec)
  149. }
  150. }
  151. func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
  152. defer unpauseAllContainers()
  153. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
  154. out, _, err := runCommandWithOutput(runCmd)
  155. if err != nil {
  156. c.Fatal(out, err)
  157. }
  158. ContainerID := strings.TrimSpace(out)
  159. pausedCmd := exec.Command(dockerBinary, "pause", "testing")
  160. out, _, _, err = runCommandWithStdoutStderr(pausedCmd)
  161. if err != nil {
  162. c.Fatal(out, err)
  163. }
  164. execCmd := exec.Command(dockerBinary, "exec", "-i", "-t", ContainerID, "echo", "hello")
  165. out, _, err = runCommandWithOutput(execCmd)
  166. if err == nil {
  167. c.Fatal("container should fail to exec new command if it is paused")
  168. }
  169. expected := ContainerID + " is paused, unpause the container before exec"
  170. if !strings.Contains(out, expected) {
  171. c.Fatal("container should not exec new command if it is paused")
  172. }
  173. }
  174. // regression test for #9476
  175. func (s *DockerSuite) TestExecTtyCloseStdin(c *check.C) {
  176. cmd := exec.Command(dockerBinary, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
  177. if out, _, err := runCommandWithOutput(cmd); err != nil {
  178. c.Fatal(out, err)
  179. }
  180. cmd = exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat")
  181. stdinRw, err := cmd.StdinPipe()
  182. if err != nil {
  183. c.Fatal(err)
  184. }
  185. stdinRw.Write([]byte("test"))
  186. stdinRw.Close()
  187. if out, _, err := runCommandWithOutput(cmd); err != nil {
  188. c.Fatal(out, err)
  189. }
  190. cmd = exec.Command(dockerBinary, "top", "exec_tty_stdin")
  191. out, _, err := runCommandWithOutput(cmd)
  192. if err != nil {
  193. c.Fatal(out, err)
  194. }
  195. outArr := strings.Split(out, "\n")
  196. if len(outArr) > 3 || strings.Contains(out, "nsenter-exec") {
  197. // This is the really bad part
  198. if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rm", "-f", "exec_tty_stdin")); err != nil {
  199. c.Fatal(out, err)
  200. }
  201. c.Fatalf("exec process left running\n\t %s", out)
  202. }
  203. }
  204. func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) {
  205. cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox")
  206. out, _, err := runCommandWithOutput(cmd)
  207. if err != nil {
  208. c.Fatalf("failed to start container: %v (%v)", out, err)
  209. }
  210. id := strings.TrimSpace(out)
  211. if err := waitRun(id); err != nil {
  212. c.Fatal(err)
  213. }
  214. defer func() {
  215. cmd := exec.Command(dockerBinary, "kill", id)
  216. if out, _, err := runCommandWithOutput(cmd); err != nil {
  217. c.Fatalf("failed to kill container: %v (%v)", out, err)
  218. }
  219. }()
  220. errChan := make(chan error)
  221. go func() {
  222. defer close(errChan)
  223. cmd := exec.Command(dockerBinary, "exec", "-ti", id, "true")
  224. if _, err := cmd.StdinPipe(); err != nil {
  225. errChan <- err
  226. return
  227. }
  228. expected := "cannot enable tty mode"
  229. if out, _, err := runCommandWithOutput(cmd); err == nil {
  230. errChan <- fmt.Errorf("exec should have failed")
  231. return
  232. } else if !strings.Contains(out, expected) {
  233. errChan <- fmt.Errorf("exec failed with error %q: expected %q", out, expected)
  234. return
  235. }
  236. }()
  237. select {
  238. case err := <-errChan:
  239. c.Assert(err, check.IsNil)
  240. case <-time.After(3 * time.Second):
  241. c.Fatal("exec is running but should have failed")
  242. }
  243. }
  244. func (s *DockerSuite) TestExecParseError(c *check.C) {
  245. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
  246. if out, _, err := runCommandWithOutput(runCmd); err != nil {
  247. c.Fatal(out, err)
  248. }
  249. // Test normal (non-detached) case first
  250. cmd := exec.Command(dockerBinary, "exec", "top")
  251. if _, stderr, code, err := runCommandWithStdoutStderr(cmd); err == nil || !strings.Contains(stderr, "See '"+dockerBinary+" exec --help'") || code == 0 {
  252. c.Fatalf("Should have thrown error & point to help: %s", stderr)
  253. }
  254. }
  255. func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
  256. if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top").CombinedOutput(); err != nil {
  257. c.Fatal(out, err)
  258. }
  259. if err := exec.Command(dockerBinary, "exec", "testing", "top").Start(); err != nil {
  260. c.Fatal(err)
  261. }
  262. type dstop struct {
  263. out []byte
  264. err error
  265. }
  266. ch := make(chan dstop)
  267. go func() {
  268. out, err := exec.Command(dockerBinary, "stop", "testing").CombinedOutput()
  269. ch <- dstop{out, err}
  270. close(ch)
  271. }()
  272. select {
  273. case <-time.After(3 * time.Second):
  274. c.Fatal("Container stop timed out")
  275. case s := <-ch:
  276. c.Assert(s.err, check.IsNil)
  277. }
  278. }
  279. func (s *DockerSuite) TestExecCgroup(c *check.C) {
  280. var cmd *exec.Cmd
  281. cmd = exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
  282. _, err := runCommand(cmd)
  283. if err != nil {
  284. c.Fatal(err)
  285. }
  286. cmd = exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/1/cgroup")
  287. out, _, err := runCommandWithOutput(cmd)
  288. if err != nil {
  289. c.Fatal(out, err)
  290. }
  291. containerCgroups := sort.StringSlice(strings.Split(string(out), "\n"))
  292. var wg sync.WaitGroup
  293. var mu sync.Mutex
  294. execCgroups := []sort.StringSlice{}
  295. errChan := make(chan error)
  296. // exec a few times concurrently to get consistent failure
  297. for i := 0; i < 5; i++ {
  298. wg.Add(1)
  299. go func() {
  300. cmd := exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/self/cgroup")
  301. out, _, err := runCommandWithOutput(cmd)
  302. if err != nil {
  303. errChan <- err
  304. return
  305. }
  306. cg := sort.StringSlice(strings.Split(string(out), "\n"))
  307. mu.Lock()
  308. execCgroups = append(execCgroups, cg)
  309. mu.Unlock()
  310. wg.Done()
  311. }()
  312. }
  313. wg.Wait()
  314. close(errChan)
  315. for err := range errChan {
  316. c.Assert(err, check.IsNil)
  317. }
  318. for _, cg := range execCgroups {
  319. if !reflect.DeepEqual(cg, containerCgroups) {
  320. fmt.Println("exec cgroups:")
  321. for _, name := range cg {
  322. fmt.Printf(" %s\n", name)
  323. }
  324. fmt.Println("container cgroups:")
  325. for _, name := range containerCgroups {
  326. fmt.Printf(" %s\n", name)
  327. }
  328. c.Fatal("cgroups mismatched")
  329. }
  330. }
  331. }
  332. func (s *DockerSuite) TestInspectExecID(c *check.C) {
  333. out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top"))
  334. if exitCode != 0 || err != nil {
  335. c.Fatalf("failed to run container: %s, %v", out, err)
  336. }
  337. id := strings.TrimSuffix(out, "\n")
  338. out, err = inspectField(id, "ExecIDs")
  339. if err != nil {
  340. c.Fatalf("failed to inspect container: %s, %v", out, err)
  341. }
  342. if out != "[]" {
  343. c.Fatalf("ExecIDs should be empty, got: %s", out)
  344. }
  345. exitCode, err = runCommand(exec.Command(dockerBinary, "exec", "-d", id, "ls", "/"))
  346. if exitCode != 0 || err != nil {
  347. c.Fatalf("failed to exec in container: %s, %v", out, err)
  348. }
  349. out, err = inspectField(id, "ExecIDs")
  350. if err != nil {
  351. c.Fatalf("failed to inspect container: %s, %v", out, err)
  352. }
  353. out = strings.TrimSuffix(out, "\n")
  354. if out == "[]" || out == "<no value>" {
  355. c.Fatalf("ExecIDs should not be empty, got: %s", out)
  356. }
  357. }
  358. func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) {
  359. var out string
  360. out, _ = dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
  361. idA := strings.TrimSpace(out)
  362. if idA == "" {
  363. c.Fatal(out, "id should not be nil")
  364. }
  365. out, _ = dockerCmd(c, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "top")
  366. idB := strings.TrimSpace(out)
  367. if idB == "" {
  368. c.Fatal(out, "id should not be nil")
  369. }
  370. execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
  371. out, _, err := runCommandWithOutput(execCmd)
  372. if err != nil {
  373. c.Fatal(out, err)
  374. }
  375. dockerCmd(c, "rename", "container1", "container_new")
  376. execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
  377. out, _, err = runCommandWithOutput(execCmd)
  378. if err != nil {
  379. c.Fatal(out, err)
  380. }
  381. }
  382. func (s *DockerSuite) TestRunExecDir(c *check.C) {
  383. testRequires(c, SameHostDaemon)
  384. cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  385. out, _, err := runCommandWithOutput(cmd)
  386. if err != nil {
  387. c.Fatal(err, out)
  388. }
  389. id := strings.TrimSpace(out)
  390. execDir := filepath.Join(execDriverPath, id)
  391. stateFile := filepath.Join(execDir, "state.json")
  392. {
  393. fi, err := os.Stat(execDir)
  394. if err != nil {
  395. c.Fatal(err)
  396. }
  397. if !fi.IsDir() {
  398. c.Fatalf("%q must be a directory", execDir)
  399. }
  400. fi, err = os.Stat(stateFile)
  401. if err != nil {
  402. c.Fatal(err)
  403. }
  404. }
  405. stopCmd := exec.Command(dockerBinary, "stop", id)
  406. out, _, err = runCommandWithOutput(stopCmd)
  407. if err != nil {
  408. c.Fatal(err, out)
  409. }
  410. {
  411. _, err := os.Stat(execDir)
  412. if err == nil {
  413. c.Fatal(err)
  414. }
  415. if err == nil {
  416. c.Fatalf("Exec directory %q exists for removed container!", execDir)
  417. }
  418. if !os.IsNotExist(err) {
  419. c.Fatalf("Error should be about non-existing, got %s", err)
  420. }
  421. }
  422. startCmd := exec.Command(dockerBinary, "start", id)
  423. out, _, err = runCommandWithOutput(startCmd)
  424. if err != nil {
  425. c.Fatal(err, out)
  426. }
  427. {
  428. fi, err := os.Stat(execDir)
  429. if err != nil {
  430. c.Fatal(err)
  431. }
  432. if !fi.IsDir() {
  433. c.Fatalf("%q must be a directory", execDir)
  434. }
  435. fi, err = os.Stat(stateFile)
  436. if err != nil {
  437. c.Fatal(err)
  438. }
  439. }
  440. rmCmd := exec.Command(dockerBinary, "rm", "-f", id)
  441. out, _, err = runCommandWithOutput(rmCmd)
  442. if err != nil {
  443. c.Fatal(err, out)
  444. }
  445. {
  446. _, err := os.Stat(execDir)
  447. if err == nil {
  448. c.Fatal(err)
  449. }
  450. if err == nil {
  451. c.Fatalf("Exec directory %q is exists for removed container!", execDir)
  452. }
  453. if !os.IsNotExist(err) {
  454. c.Fatalf("Error should be about non-existing, got %s", err)
  455. }
  456. }
  457. }
  458. func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
  459. testRequires(c, SameHostDaemon)
  460. for _, fn := range []string{"resolv.conf", "hosts"} {
  461. deleteAllContainers()
  462. content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn)))
  463. if err != nil {
  464. c.Fatal(err)
  465. }
  466. if strings.TrimSpace(string(content)) != "success" {
  467. c.Fatal("Content was not what was modified in the container", string(content))
  468. }
  469. out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "top"))
  470. if err != nil {
  471. c.Fatal(err)
  472. }
  473. contID := strings.TrimSpace(out)
  474. netFilePath := containerStorageFile(contID, fn)
  475. f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
  476. if err != nil {
  477. c.Fatal(err)
  478. }
  479. if _, err := f.Seek(0, 0); err != nil {
  480. f.Close()
  481. c.Fatal(err)
  482. }
  483. if err := f.Truncate(0); err != nil {
  484. f.Close()
  485. c.Fatal(err)
  486. }
  487. if _, err := f.Write([]byte("success2\n")); err != nil {
  488. f.Close()
  489. c.Fatal(err)
  490. }
  491. f.Close()
  492. res, err := exec.Command(dockerBinary, "exec", contID, "cat", "/etc/"+fn).CombinedOutput()
  493. if err != nil {
  494. c.Fatalf("Output: %s, error: %s", res, err)
  495. }
  496. if string(res) != "success2\n" {
  497. c.Fatalf("Expected content of %s: %q, got: %q", fn, "success2\n", res)
  498. }
  499. }
  500. }
  501. func (s *DockerSuite) TestExecWithUser(c *check.C) {
  502. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
  503. if out, _, err := runCommandWithOutput(runCmd); err != nil {
  504. c.Fatal(out, err)
  505. }
  506. cmd := exec.Command(dockerBinary, "exec", "-u", "1", "parent", "id")
  507. out, _, err := runCommandWithOutput(cmd)
  508. if err != nil {
  509. c.Fatal(err, out)
  510. }
  511. if !strings.Contains(out, "uid=1(daemon) gid=1(daemon)") {
  512. c.Fatalf("exec with user by id expected daemon user got %s", out)
  513. }
  514. cmd = exec.Command(dockerBinary, "exec", "-u", "root", "parent", "id")
  515. out, _, err = runCommandWithOutput(cmd)
  516. if err != nil {
  517. c.Fatal(err, out)
  518. }
  519. if !strings.Contains(out, "uid=0(root) gid=0(root)") {
  520. c.Fatalf("exec with user by root expected root user got %s", out)
  521. }
  522. }
  523. func (s *DockerSuite) TestExecWithPrivileged(c *check.C) {
  524. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "--cap-drop=ALL", "busybox", "top")
  525. if out, _, err := runCommandWithOutput(runCmd); err != nil {
  526. c.Fatal(out, err)
  527. }
  528. cmd := exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sda b 8 0")
  529. out, _, err := runCommandWithOutput(cmd)
  530. if err == nil || !strings.Contains(out, "Operation not permitted") {
  531. c.Fatalf("exec mknod in --cap-drop=ALL container without --privileged should failed")
  532. }
  533. cmd = exec.Command(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
  534. out, _, err = runCommandWithOutput(cmd)
  535. if err != nil {
  536. c.Fatal(err, out)
  537. }
  538. if actual := strings.TrimSpace(out); actual != "ok" {
  539. c.Fatalf("exec mknod in --cap-drop=ALL container with --privileged failed: %v, output: %q", err, out)
  540. }
  541. }