docker_cli_exec_test.go 17 KB

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