docker_api_containers_test.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. package main
  2. import (
  3. "archive/tar"
  4. "bytes"
  5. "encoding/json"
  6. "io"
  7. "net/http"
  8. "net/http/httputil"
  9. "os"
  10. "os/exec"
  11. "strings"
  12. "time"
  13. "github.com/docker/docker/api/types"
  14. "github.com/docker/docker/pkg/stringid"
  15. "github.com/go-check/check"
  16. )
  17. func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
  18. startCount, err := getContainerCount()
  19. if err != nil {
  20. c.Fatalf("Cannot query container count: %v", err)
  21. }
  22. name := "getall"
  23. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
  24. out, _, err := runCommandWithOutput(runCmd)
  25. if err != nil {
  26. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  27. }
  28. status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
  29. c.Assert(status, check.Equals, http.StatusOK)
  30. c.Assert(err, check.IsNil)
  31. var inspectJSON []struct {
  32. Names []string
  33. }
  34. if err = json.Unmarshal(body, &inspectJSON); err != nil {
  35. c.Fatalf("unable to unmarshal response body: %v", err)
  36. }
  37. if len(inspectJSON) != startCount+1 {
  38. c.Fatalf("Expected %d container(s), %d found (started with: %d)", startCount+1, len(inspectJSON), startCount)
  39. }
  40. if actual := inspectJSON[0].Names[0]; actual != "/"+name {
  41. c.Fatalf("Container Name mismatch. Expected: %q, received: %q\n", "/"+name, actual)
  42. }
  43. }
  44. func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
  45. name := "exportcontainer"
  46. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
  47. out, _, err := runCommandWithOutput(runCmd)
  48. if err != nil {
  49. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  50. }
  51. status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
  52. c.Assert(status, check.Equals, http.StatusOK)
  53. c.Assert(err, check.IsNil)
  54. found := false
  55. for tarReader := tar.NewReader(bytes.NewReader(body)); ; {
  56. h, err := tarReader.Next()
  57. if err != nil {
  58. if err == io.EOF {
  59. break
  60. }
  61. c.Fatal(err)
  62. }
  63. if h.Name == "test" {
  64. found = true
  65. break
  66. }
  67. }
  68. if !found {
  69. c.Fatalf("The created test file has not been found in the exported image")
  70. }
  71. }
  72. func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
  73. name := "changescontainer"
  74. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "rm", "/etc/passwd")
  75. out, _, err := runCommandWithOutput(runCmd)
  76. if err != nil {
  77. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  78. }
  79. status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
  80. c.Assert(status, check.Equals, http.StatusOK)
  81. c.Assert(err, check.IsNil)
  82. changes := []struct {
  83. Kind int
  84. Path string
  85. }{}
  86. if err = json.Unmarshal(body, &changes); err != nil {
  87. c.Fatalf("unable to unmarshal response body: %v", err)
  88. }
  89. // Check the changelog for removal of /etc/passwd
  90. success := false
  91. for _, elem := range changes {
  92. if elem.Path == "/etc/passwd" && elem.Kind == 2 {
  93. success = true
  94. }
  95. }
  96. if !success {
  97. c.Fatalf("/etc/passwd has been removed but is not present in the diff")
  98. }
  99. }
  100. func (s *DockerSuite) TestContainerApiStartVolumeBinds(c *check.C) {
  101. name := "testing"
  102. config := map[string]interface{}{
  103. "Image": "busybox",
  104. "Volumes": map[string]struct{}{"/tmp": {}},
  105. }
  106. status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
  107. c.Assert(status, check.Equals, http.StatusCreated)
  108. c.Assert(err, check.IsNil)
  109. bindPath := randomUnixTmpDirPath("test")
  110. config = map[string]interface{}{
  111. "Binds": []string{bindPath + ":/tmp"},
  112. }
  113. status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
  114. c.Assert(status, check.Equals, http.StatusNoContent)
  115. c.Assert(err, check.IsNil)
  116. pth, err := inspectFieldMap(name, "Volumes", "/tmp")
  117. if err != nil {
  118. c.Fatal(err)
  119. }
  120. if pth != bindPath {
  121. c.Fatalf("expected volume host path to be %s, got %s", bindPath, pth)
  122. }
  123. }
  124. // Test for GH#10618
  125. func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
  126. name := "testdups"
  127. config := map[string]interface{}{
  128. "Image": "busybox",
  129. "Volumes": map[string]struct{}{"/tmp": {}},
  130. }
  131. status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
  132. c.Assert(status, check.Equals, http.StatusCreated)
  133. c.Assert(err, check.IsNil)
  134. bindPath1 := randomUnixTmpDirPath("test1")
  135. bindPath2 := randomUnixTmpDirPath("test2")
  136. config = map[string]interface{}{
  137. "Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
  138. }
  139. status, body, err := sockRequest("POST", "/containers/"+name+"/start", config)
  140. c.Assert(status, check.Equals, http.StatusInternalServerError)
  141. c.Assert(err, check.IsNil)
  142. if !strings.Contains(string(body), "Duplicate volume") {
  143. c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
  144. }
  145. }
  146. func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
  147. volName := "voltst"
  148. volPath := "/tmp"
  149. if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", volName, "-v", volPath, "busybox")); err != nil {
  150. c.Fatal(out, err)
  151. }
  152. name := "TestContainerApiStartDupVolumeBinds"
  153. config := map[string]interface{}{
  154. "Image": "busybox",
  155. "Volumes": map[string]struct{}{volPath: {}},
  156. }
  157. status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
  158. c.Assert(status, check.Equals, http.StatusCreated)
  159. c.Assert(err, check.IsNil)
  160. config = map[string]interface{}{
  161. "VolumesFrom": []string{volName},
  162. }
  163. status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
  164. c.Assert(status, check.Equals, http.StatusNoContent)
  165. c.Assert(err, check.IsNil)
  166. pth, err := inspectFieldMap(name, "Volumes", volPath)
  167. if err != nil {
  168. c.Fatal(err)
  169. }
  170. pth2, err := inspectFieldMap(volName, "Volumes", volPath)
  171. if err != nil {
  172. c.Fatal(err)
  173. }
  174. if pth != pth2 {
  175. c.Fatalf("expected volume host path to be %s, got %s", pth, pth2)
  176. }
  177. }
  178. // Ensure that volumes-from has priority over binds/anything else
  179. // This is pretty much the same as TestRunApplyVolumesFromBeforeVolumes, except with passing the VolumesFrom and the bind on start
  180. func (s *DockerSuite) TestVolumesFromHasPriority(c *check.C) {
  181. volName := "voltst2"
  182. volPath := "/tmp"
  183. if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", volName, "-v", volPath, "busybox")); err != nil {
  184. c.Fatal(out, err)
  185. }
  186. name := "testing"
  187. config := map[string]interface{}{
  188. "Image": "busybox",
  189. "Volumes": map[string]struct{}{volPath: {}},
  190. }
  191. status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
  192. c.Assert(status, check.Equals, http.StatusCreated)
  193. c.Assert(err, check.IsNil)
  194. bindPath := randomUnixTmpDirPath("test")
  195. config = map[string]interface{}{
  196. "VolumesFrom": []string{volName},
  197. "Binds": []string{bindPath + ":/tmp"},
  198. }
  199. status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
  200. c.Assert(status, check.Equals, http.StatusNoContent)
  201. c.Assert(err, check.IsNil)
  202. pth, err := inspectFieldMap(name, "Volumes", volPath)
  203. if err != nil {
  204. c.Fatal(err)
  205. }
  206. pth2, err := inspectFieldMap(volName, "Volumes", volPath)
  207. if err != nil {
  208. c.Fatal(err)
  209. }
  210. if pth != pth2 {
  211. c.Fatalf("expected volume host path to be %s, got %s", pth, pth2)
  212. }
  213. }
  214. func (s *DockerSuite) TestGetContainerStats(c *check.C) {
  215. var (
  216. name = "statscontainer"
  217. runCmd = exec.Command(dockerBinary, "run", "-d", "--name", name, "busybox", "top")
  218. )
  219. out, _, err := runCommandWithOutput(runCmd)
  220. if err != nil {
  221. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  222. }
  223. type b struct {
  224. status int
  225. body []byte
  226. err error
  227. }
  228. bc := make(chan b, 1)
  229. go func() {
  230. status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
  231. bc <- b{status, body, err}
  232. }()
  233. // allow some time to stream the stats from the container
  234. time.Sleep(4 * time.Second)
  235. if _, err := runCommand(exec.Command(dockerBinary, "rm", "-f", name)); err != nil {
  236. c.Fatal(err)
  237. }
  238. // collect the results from the stats stream or timeout and fail
  239. // if the stream was not disconnected.
  240. select {
  241. case <-time.After(2 * time.Second):
  242. c.Fatal("stream was not closed after container was removed")
  243. case sr := <-bc:
  244. c.Assert(sr.err, check.IsNil)
  245. c.Assert(sr.status, check.Equals, http.StatusOK)
  246. dec := json.NewDecoder(bytes.NewBuffer(sr.body))
  247. var s *types.Stats
  248. // decode only one object from the stream
  249. if err := dec.Decode(&s); err != nil {
  250. c.Fatal(err)
  251. }
  252. }
  253. }
  254. func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
  255. // TODO: this test does nothing because we are c.Assert'ing in goroutine
  256. var (
  257. name = "statscontainer"
  258. runCmd = exec.Command(dockerBinary, "create", "--name", name, "busybox", "top")
  259. )
  260. out, _, err := runCommandWithOutput(runCmd)
  261. if err != nil {
  262. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  263. }
  264. go func() {
  265. // We'll never get return for GET stats from sockRequest as of now,
  266. // just send request and see if panic or error would happen on daemon side.
  267. status, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
  268. c.Assert(status, check.Equals, http.StatusOK)
  269. c.Assert(err, check.IsNil)
  270. }()
  271. // allow some time to send request and let daemon deal with it
  272. time.Sleep(1 * time.Second)
  273. }
  274. func (s *DockerSuite) TestBuildApiDockerfilePath(c *check.C) {
  275. // Test to make sure we stop people from trying to leave the
  276. // build context when specifying the path to the dockerfile
  277. buffer := new(bytes.Buffer)
  278. tw := tar.NewWriter(buffer)
  279. defer tw.Close()
  280. dockerfile := []byte("FROM busybox")
  281. if err := tw.WriteHeader(&tar.Header{
  282. Name: "Dockerfile",
  283. Size: int64(len(dockerfile)),
  284. }); err != nil {
  285. c.Fatalf("failed to write tar file header: %v", err)
  286. }
  287. if _, err := tw.Write(dockerfile); err != nil {
  288. c.Fatalf("failed to write tar file content: %v", err)
  289. }
  290. if err := tw.Close(); err != nil {
  291. c.Fatalf("failed to close tar archive: %v", err)
  292. }
  293. res, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
  294. c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
  295. c.Assert(err, check.IsNil)
  296. out, err := readBody(body)
  297. if err != nil {
  298. c.Fatal(err)
  299. }
  300. if !strings.Contains(string(out), "must be within the build context") {
  301. c.Fatalf("Didn't complain about leaving build context: %s", out)
  302. }
  303. }
  304. func (s *DockerSuite) TestBuildApiDockerFileRemote(c *check.C) {
  305. server, err := fakeStorage(map[string]string{
  306. "testD": `FROM busybox
  307. COPY * /tmp/
  308. RUN find / -name ba*
  309. RUN find /tmp/`,
  310. })
  311. if err != nil {
  312. c.Fatal(err)
  313. }
  314. defer server.Close()
  315. res, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
  316. c.Assert(res.StatusCode, check.Equals, http.StatusOK)
  317. c.Assert(err, check.IsNil)
  318. buf, err := readBody(body)
  319. if err != nil {
  320. c.Fatal(err)
  321. }
  322. // Make sure Dockerfile exists.
  323. // Make sure 'baz' doesn't exist ANYWHERE despite being mentioned in the URL
  324. out := string(buf)
  325. if !strings.Contains(out, "/tmp/Dockerfile") ||
  326. strings.Contains(out, "baz") {
  327. c.Fatalf("Incorrect output: %s", out)
  328. }
  329. }
  330. func (s *DockerSuite) TestBuildApiLowerDockerfile(c *check.C) {
  331. git, err := fakeGIT("repo", map[string]string{
  332. "dockerfile": `FROM busybox
  333. RUN echo from dockerfile`,
  334. }, false)
  335. if err != nil {
  336. c.Fatal(err)
  337. }
  338. defer git.Close()
  339. res, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
  340. c.Assert(res.StatusCode, check.Equals, http.StatusOK)
  341. c.Assert(err, check.IsNil)
  342. buf, err := readBody(body)
  343. if err != nil {
  344. c.Fatal(err)
  345. }
  346. out := string(buf)
  347. if !strings.Contains(out, "from dockerfile") {
  348. c.Fatalf("Incorrect output: %s", out)
  349. }
  350. }
  351. func (s *DockerSuite) TestBuildApiBuildGitWithF(c *check.C) {
  352. git, err := fakeGIT("repo", map[string]string{
  353. "baz": `FROM busybox
  354. RUN echo from baz`,
  355. "Dockerfile": `FROM busybox
  356. RUN echo from Dockerfile`,
  357. }, false)
  358. if err != nil {
  359. c.Fatal(err)
  360. }
  361. defer git.Close()
  362. // Make sure it tries to 'dockerfile' query param value
  363. res, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
  364. c.Assert(res.StatusCode, check.Equals, http.StatusOK)
  365. c.Assert(err, check.IsNil)
  366. buf, err := readBody(body)
  367. if err != nil {
  368. c.Fatal(err)
  369. }
  370. out := string(buf)
  371. if !strings.Contains(out, "from baz") {
  372. c.Fatalf("Incorrect output: %s", out)
  373. }
  374. }
  375. func (s *DockerSuite) TestBuildApiDoubleDockerfile(c *check.C) {
  376. testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows
  377. git, err := fakeGIT("repo", map[string]string{
  378. "Dockerfile": `FROM busybox
  379. RUN echo from Dockerfile`,
  380. "dockerfile": `FROM busybox
  381. RUN echo from dockerfile`,
  382. }, false)
  383. if err != nil {
  384. c.Fatal(err)
  385. }
  386. defer git.Close()
  387. // Make sure it tries to 'dockerfile' query param value
  388. res, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
  389. c.Assert(res.StatusCode, check.Equals, http.StatusOK)
  390. c.Assert(err, check.IsNil)
  391. buf, err := readBody(body)
  392. if err != nil {
  393. c.Fatal(err)
  394. }
  395. out := string(buf)
  396. if !strings.Contains(out, "from Dockerfile") {
  397. c.Fatalf("Incorrect output: %s", out)
  398. }
  399. }
  400. func (s *DockerSuite) TestBuildApiDockerfileSymlink(c *check.C) {
  401. // Test to make sure we stop people from trying to leave the
  402. // build context when specifying a symlink as the path to the dockerfile
  403. buffer := new(bytes.Buffer)
  404. tw := tar.NewWriter(buffer)
  405. defer tw.Close()
  406. if err := tw.WriteHeader(&tar.Header{
  407. Name: "Dockerfile",
  408. Typeflag: tar.TypeSymlink,
  409. Linkname: "/etc/passwd",
  410. }); err != nil {
  411. c.Fatalf("failed to write tar file header: %v", err)
  412. }
  413. if err := tw.Close(); err != nil {
  414. c.Fatalf("failed to close tar archive: %v", err)
  415. }
  416. res, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
  417. c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
  418. c.Assert(err, check.IsNil)
  419. out, err := readBody(body)
  420. if err != nil {
  421. c.Fatal(err)
  422. }
  423. // The reason the error is "Cannot locate specified Dockerfile" is because
  424. // in the builder, the symlink is resolved within the context, therefore
  425. // Dockerfile -> /etc/passwd becomes etc/passwd from the context which is
  426. // a nonexistent file.
  427. if !strings.Contains(string(out), "Cannot locate specified Dockerfile: Dockerfile") {
  428. c.Fatalf("Didn't complain about leaving build context: %s", out)
  429. }
  430. }
  431. // #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume
  432. func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
  433. out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=one", "busybox"))
  434. if err != nil {
  435. c.Fatal(err, out)
  436. }
  437. fooDir, err := inspectFieldMap("one", "Volumes", "/foo")
  438. if err != nil {
  439. c.Fatal(err)
  440. }
  441. out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "create", "-v", "/foo", "--name=two", "busybox"))
  442. if err != nil {
  443. c.Fatal(err, out)
  444. }
  445. bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
  446. status, _, err := sockRequest("POST", "/containers/two/start", bindSpec)
  447. c.Assert(status, check.Equals, http.StatusNoContent)
  448. c.Assert(err, check.IsNil)
  449. fooDir2, err := inspectFieldMap("two", "Volumes", "/foo")
  450. if err != nil {
  451. c.Fatal(err)
  452. }
  453. if fooDir2 != fooDir {
  454. c.Fatalf("expected volume path to be %s, got: %s", fooDir, fooDir2)
  455. }
  456. }
  457. func (s *DockerSuite) TestContainerApiPause(c *check.C) {
  458. defer unpauseAllContainers()
  459. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "30")
  460. out, _, err := runCommandWithOutput(runCmd)
  461. if err != nil {
  462. c.Fatalf("failed to create a container: %s, %v", out, err)
  463. }
  464. ContainerID := strings.TrimSpace(out)
  465. status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
  466. c.Assert(status, check.Equals, http.StatusNoContent)
  467. c.Assert(err, check.IsNil)
  468. pausedContainers, err := getSliceOfPausedContainers()
  469. if err != nil {
  470. c.Fatalf("error thrown while checking if containers were paused: %v", err)
  471. }
  472. if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] {
  473. c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
  474. }
  475. status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
  476. c.Assert(status, check.Equals, http.StatusNoContent)
  477. c.Assert(err, check.IsNil)
  478. pausedContainers, err = getSliceOfPausedContainers()
  479. if err != nil {
  480. c.Fatalf("error thrown while checking if containers were paused: %v", err)
  481. }
  482. if pausedContainers != nil {
  483. c.Fatalf("There should be no paused container.")
  484. }
  485. }
  486. func (s *DockerSuite) TestContainerApiTop(c *check.C) {
  487. out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "top").CombinedOutput()
  488. if err != nil {
  489. c.Fatal(err, out)
  490. }
  491. id := strings.TrimSpace(string(out))
  492. if err := waitRun(id); err != nil {
  493. c.Fatal(err)
  494. }
  495. type topResp struct {
  496. Titles []string
  497. Processes [][]string
  498. }
  499. var top topResp
  500. status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
  501. c.Assert(status, check.Equals, http.StatusOK)
  502. c.Assert(err, check.IsNil)
  503. if err := json.Unmarshal(b, &top); err != nil {
  504. c.Fatal(err)
  505. }
  506. if len(top.Titles) != 11 {
  507. c.Fatalf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles)
  508. }
  509. if top.Titles[0] != "USER" || top.Titles[10] != "COMMAND" {
  510. c.Fatalf("expected `USER` at `Titles[0]` and `COMMAND` at Titles[10]: %v", top.Titles)
  511. }
  512. if len(top.Processes) != 2 {
  513. c.Fatalf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes)
  514. }
  515. if top.Processes[0][10] != "/bin/sh -c top" {
  516. c.Fatalf("expected `/bin/sh -c top`, found: %s", top.Processes[0][10])
  517. }
  518. if top.Processes[1][10] != "top" {
  519. c.Fatalf("expected `top`, found: %s", top.Processes[1][10])
  520. }
  521. }
  522. func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
  523. cName := "testapicommit"
  524. out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput()
  525. if err != nil {
  526. c.Fatal(err, out)
  527. }
  528. name := "TestContainerApiCommit"
  529. status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil)
  530. c.Assert(status, check.Equals, http.StatusCreated)
  531. c.Assert(err, check.IsNil)
  532. type resp struct {
  533. Id string
  534. }
  535. var img resp
  536. if err := json.Unmarshal(b, &img); err != nil {
  537. c.Fatal(err)
  538. }
  539. cmd, err := inspectField(img.Id, "Config.Cmd")
  540. if err != nil {
  541. c.Fatal(err)
  542. }
  543. if cmd != "{[/bin/sh -c touch /test]}" {
  544. c.Fatalf("got wrong Cmd from commit: %q", cmd)
  545. }
  546. // sanity check, make sure the image is what we think it is
  547. out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput()
  548. if err != nil {
  549. c.Fatalf("error checking committed image: %v - %q", err, string(out))
  550. }
  551. }
  552. func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
  553. config := map[string]interface{}{
  554. "Image": "busybox",
  555. "Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
  556. }
  557. status, b, err := sockRequest("POST", "/containers/create", config)
  558. c.Assert(status, check.Equals, http.StatusCreated)
  559. c.Assert(err, check.IsNil)
  560. type createResp struct {
  561. Id string
  562. }
  563. var container createResp
  564. if err := json.Unmarshal(b, &container); err != nil {
  565. c.Fatal(err)
  566. }
  567. out, err := exec.Command(dockerBinary, "start", "-a", container.Id).CombinedOutput()
  568. if err != nil {
  569. c.Fatal(out, err)
  570. }
  571. if strings.TrimSpace(string(out)) != "/test" {
  572. c.Fatalf("expected output `/test`, got %q", out)
  573. }
  574. }
  575. func (s *DockerSuite) TestContainerApiCreateWithHostName(c *check.C) {
  576. var hostName = "test-host"
  577. config := map[string]interface{}{
  578. "Image": "busybox",
  579. "Hostname": hostName,
  580. }
  581. _, b, err := sockRequest("POST", "/containers/create", config)
  582. if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
  583. c.Fatal(err)
  584. }
  585. type createResp struct {
  586. Id string
  587. }
  588. var container createResp
  589. if err := json.Unmarshal(b, &container); err != nil {
  590. c.Fatal(err)
  591. }
  592. var id = container.Id
  593. _, bodyGet, err := sockRequest("GET", "/containers/"+id+"/json", nil)
  594. type configLocal struct {
  595. Hostname string
  596. }
  597. type getResponse struct {
  598. Id string
  599. Config configLocal
  600. }
  601. var containerInfo getResponse
  602. if err := json.Unmarshal(bodyGet, &containerInfo); err != nil {
  603. c.Fatal(err)
  604. }
  605. var hostNameActual = containerInfo.Config.Hostname
  606. if hostNameActual != "test-host" {
  607. c.Fatalf("Mismatched Hostname, Expected %v, Actual: %v ", hostName, hostNameActual)
  608. }
  609. }
  610. func (s *DockerSuite) TestContainerApiVerifyHeader(c *check.C) {
  611. config := map[string]interface{}{
  612. "Image": "busybox",
  613. }
  614. create := func(ct string) (*http.Response, io.ReadCloser, error) {
  615. jsonData := bytes.NewBuffer(nil)
  616. if err := json.NewEncoder(jsonData).Encode(config); err != nil {
  617. c.Fatal(err)
  618. }
  619. return sockRequestRaw("POST", "/containers/create", jsonData, ct)
  620. }
  621. // Try with no content-type
  622. res, body, err := create("")
  623. c.Assert(err, check.IsNil)
  624. c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
  625. body.Close()
  626. // Try with wrong content-type
  627. res, body, err = create("application/xml")
  628. c.Assert(err, check.IsNil)
  629. c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
  630. body.Close()
  631. // now application/json
  632. res, body, err = create("application/json")
  633. c.Assert(err, check.IsNil)
  634. c.Assert(res.StatusCode, check.Equals, http.StatusCreated)
  635. body.Close()
  636. }
  637. // Issue 7941 - test to make sure a "null" in JSON is just ignored.
  638. // W/o this fix a null in JSON would be parsed into a string var as "null"
  639. func (s *DockerSuite) TestContainerApiPostCreateNull(c *check.C) {
  640. config := `{
  641. "Hostname":"",
  642. "Domainname":"",
  643. "Memory":0,
  644. "MemorySwap":0,
  645. "CpuShares":0,
  646. "Cpuset":null,
  647. "AttachStdin":true,
  648. "AttachStdout":true,
  649. "AttachStderr":true,
  650. "PortSpecs":null,
  651. "ExposedPorts":{},
  652. "Tty":true,
  653. "OpenStdin":true,
  654. "StdinOnce":true,
  655. "Env":[],
  656. "Cmd":"ls",
  657. "Image":"busybox",
  658. "Volumes":{},
  659. "WorkingDir":"",
  660. "Entrypoint":null,
  661. "NetworkDisabled":false,
  662. "OnBuild":null}`
  663. res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
  664. c.Assert(res.StatusCode, check.Equals, http.StatusCreated)
  665. c.Assert(err, check.IsNil)
  666. b, err := readBody(body)
  667. if err != nil {
  668. c.Fatal(err)
  669. }
  670. type createResp struct {
  671. Id string
  672. }
  673. var container createResp
  674. if err := json.Unmarshal(b, &container); err != nil {
  675. c.Fatal(err)
  676. }
  677. out, err := inspectField(container.Id, "HostConfig.CpusetCpus")
  678. if err != nil {
  679. c.Fatal(err, out)
  680. }
  681. if out != "" {
  682. c.Fatalf("expected empty string, got %q", out)
  683. }
  684. }
  685. func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
  686. config := `{
  687. "Image": "busybox",
  688. "Cmd": "ls",
  689. "OpenStdin": true,
  690. "CpuShares": 100,
  691. "Memory": 524287
  692. }`
  693. res, body, _ := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
  694. b, err2 := readBody(body)
  695. if err2 != nil {
  696. c.Fatal(err2)
  697. }
  698. c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
  699. c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
  700. }
  701. func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
  702. out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "busybox"))
  703. if err != nil {
  704. c.Fatal(err, out)
  705. }
  706. containerID := strings.TrimSpace(out)
  707. config := `{
  708. "CpuShares": 100,
  709. "Memory": 524287
  710. }`
  711. res, body, _ := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
  712. b, err2 := readBody(body)
  713. if err2 != nil {
  714. c.Fatal(err2)
  715. }
  716. c.Assert(res.StatusCode, check.Equals, http.StatusInternalServerError)
  717. c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
  718. }
  719. func (s *DockerSuite) TestContainerApiRename(c *check.C) {
  720. runCmd := exec.Command(dockerBinary, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
  721. out, _, err := runCommandWithOutput(runCmd)
  722. c.Assert(err, check.IsNil)
  723. containerID := strings.TrimSpace(out)
  724. newName := "TestContainerApiRenameNew"
  725. statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil)
  726. // 204 No Content is expected, not 200
  727. c.Assert(statusCode, check.Equals, http.StatusNoContent)
  728. c.Assert(err, check.IsNil)
  729. name, err := inspectField(containerID, "Name")
  730. if name != "/"+newName {
  731. c.Fatalf("Failed to rename container, expected %v, got %v. Container rename API failed", newName, name)
  732. }
  733. }
  734. func (s *DockerSuite) TestContainerApiKill(c *check.C) {
  735. name := "test-api-kill"
  736. runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
  737. out, _, err := runCommandWithOutput(runCmd)
  738. if err != nil {
  739. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  740. }
  741. status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil)
  742. c.Assert(status, check.Equals, http.StatusNoContent)
  743. c.Assert(err, check.IsNil)
  744. state, err := inspectField(name, "State.Running")
  745. if err != nil {
  746. c.Fatal(err)
  747. }
  748. if state != "false" {
  749. c.Fatalf("got wrong State from container %s: %q", name, state)
  750. }
  751. }
  752. func (s *DockerSuite) TestContainerApiRestart(c *check.C) {
  753. name := "test-api-restart"
  754. runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
  755. out, _, err := runCommandWithOutput(runCmd)
  756. if err != nil {
  757. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  758. }
  759. status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil)
  760. c.Assert(status, check.Equals, http.StatusNoContent)
  761. c.Assert(err, check.IsNil)
  762. if err := waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 5); err != nil {
  763. c.Fatal(err)
  764. }
  765. }
  766. func (s *DockerSuite) TestContainerApiStart(c *check.C) {
  767. name := "testing-start"
  768. config := map[string]interface{}{
  769. "Image": "busybox",
  770. "Cmd": []string{"/bin/sh", "-c", "/bin/top"},
  771. "OpenStdin": true,
  772. }
  773. status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
  774. c.Assert(status, check.Equals, http.StatusCreated)
  775. c.Assert(err, check.IsNil)
  776. conf := make(map[string]interface{})
  777. status, _, err = sockRequest("POST", "/containers/"+name+"/start", conf)
  778. c.Assert(status, check.Equals, http.StatusNoContent)
  779. c.Assert(err, check.IsNil)
  780. // second call to start should give 304
  781. status, _, err = sockRequest("POST", "/containers/"+name+"/start", conf)
  782. c.Assert(status, check.Equals, http.StatusNotModified)
  783. c.Assert(err, check.IsNil)
  784. }
  785. func (s *DockerSuite) TestContainerApiStop(c *check.C) {
  786. name := "test-api-stop"
  787. runCmd := exec.Command(dockerBinary, "run", "-di", "--name", name, "busybox", "top")
  788. out, _, err := runCommandWithOutput(runCmd)
  789. if err != nil {
  790. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  791. }
  792. status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=1", nil)
  793. c.Assert(status, check.Equals, http.StatusNoContent)
  794. c.Assert(err, check.IsNil)
  795. if err := waitInspect(name, "{{ .State.Running }}", "false", 5); err != nil {
  796. c.Fatal(err)
  797. }
  798. // second call to start should give 304
  799. status, _, err = sockRequest("POST", "/containers/"+name+"/stop?t=1", nil)
  800. c.Assert(status, check.Equals, http.StatusNotModified)
  801. c.Assert(err, check.IsNil)
  802. }
  803. func (s *DockerSuite) TestContainerApiWait(c *check.C) {
  804. name := "test-api-wait"
  805. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sleep", "5")
  806. out, _, err := runCommandWithOutput(runCmd)
  807. if err != nil {
  808. c.Fatalf("Error on container creation: %v, output: %q", err, out)
  809. }
  810. status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil)
  811. c.Assert(status, check.Equals, http.StatusOK)
  812. c.Assert(err, check.IsNil)
  813. if err := waitInspect(name, "{{ .State.Running }}", "false", 5); err != nil {
  814. c.Fatal(err)
  815. }
  816. var waitres types.ContainerWaitResponse
  817. if err := json.Unmarshal(body, &waitres); err != nil {
  818. c.Fatalf("unable to unmarshal response body: %v", err)
  819. }
  820. if waitres.StatusCode != 0 {
  821. c.Fatalf("Expected wait response StatusCode to be 0, got %d", waitres.StatusCode)
  822. }
  823. }
  824. func (s *DockerSuite) TestContainerApiCopy(c *check.C) {
  825. name := "test-container-api-copy"
  826. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt")
  827. _, err := runCommand(runCmd)
  828. c.Assert(err, check.IsNil)
  829. postData := types.CopyConfig{
  830. Resource: "/test.txt",
  831. }
  832. status, body, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
  833. c.Assert(err, check.IsNil)
  834. c.Assert(status, check.Equals, http.StatusOK)
  835. found := false
  836. for tarReader := tar.NewReader(bytes.NewReader(body)); ; {
  837. h, err := tarReader.Next()
  838. if err != nil {
  839. if err == io.EOF {
  840. break
  841. }
  842. c.Fatal(err)
  843. }
  844. if h.Name == "test.txt" {
  845. found = true
  846. break
  847. }
  848. }
  849. c.Assert(found, check.Equals, true)
  850. }
  851. func (s *DockerSuite) TestContainerApiCopyResourcePathEmpty(c *check.C) {
  852. name := "test-container-api-copy-resource-empty"
  853. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test.txt")
  854. _, err := runCommand(runCmd)
  855. c.Assert(err, check.IsNil)
  856. postData := types.CopyConfig{
  857. Resource: "",
  858. }
  859. status, body, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
  860. c.Assert(err, check.IsNil)
  861. c.Assert(status, check.Equals, http.StatusInternalServerError)
  862. c.Assert(string(body), check.Matches, "Path cannot be empty\n")
  863. }
  864. func (s *DockerSuite) TestContainerApiCopyResourcePathNotFound(c *check.C) {
  865. name := "test-container-api-copy-resource-not-found"
  866. runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox")
  867. _, err := runCommand(runCmd)
  868. c.Assert(err, check.IsNil)
  869. postData := types.CopyConfig{
  870. Resource: "/notexist",
  871. }
  872. status, body, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
  873. c.Assert(err, check.IsNil)
  874. c.Assert(status, check.Equals, http.StatusInternalServerError)
  875. c.Assert(string(body), check.Matches, "Could not find the file /notexist in container "+name+"\n")
  876. }
  877. func (s *DockerSuite) TestContainerApiCopyContainerNotFound(c *check.C) {
  878. postData := types.CopyConfig{
  879. Resource: "/something",
  880. }
  881. status, _, err := sockRequest("POST", "/containers/notexists/copy", postData)
  882. c.Assert(err, check.IsNil)
  883. c.Assert(status, check.Equals, http.StatusNotFound)
  884. }
  885. func (s *DockerSuite) TestContainerApiDelete(c *check.C) {
  886. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  887. out, _, err := runCommandWithOutput(runCmd)
  888. c.Assert(err, check.IsNil)
  889. id := strings.TrimSpace(out)
  890. c.Assert(waitRun(id), check.IsNil)
  891. stopCmd := exec.Command(dockerBinary, "stop", id)
  892. _, err = runCommand(stopCmd)
  893. c.Assert(err, check.IsNil)
  894. status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
  895. c.Assert(err, check.IsNil)
  896. c.Assert(status, check.Equals, http.StatusNoContent)
  897. }
  898. func (s *DockerSuite) TestContainerApiDeleteNotExist(c *check.C) {
  899. status, body, err := sockRequest("DELETE", "/containers/doesnotexist", nil)
  900. c.Assert(err, check.IsNil)
  901. c.Assert(status, check.Equals, http.StatusNotFound)
  902. c.Assert(string(body), check.Matches, "no such id: doesnotexist\n")
  903. }
  904. func (s *DockerSuite) TestContainerApiDeleteForce(c *check.C) {
  905. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  906. out, _, err := runCommandWithOutput(runCmd)
  907. c.Assert(err, check.IsNil)
  908. id := strings.TrimSpace(out)
  909. c.Assert(waitRun(id), check.IsNil)
  910. status, _, err := sockRequest("DELETE", "/containers/"+id+"?force=1", nil)
  911. c.Assert(err, check.IsNil)
  912. c.Assert(status, check.Equals, http.StatusNoContent)
  913. }
  914. func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
  915. runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "tlink1", "busybox", "top")
  916. out, _, err := runCommandWithOutput(runCmd)
  917. c.Assert(err, check.IsNil)
  918. id := strings.TrimSpace(out)
  919. c.Assert(waitRun(id), check.IsNil)
  920. runCmd = exec.Command(dockerBinary, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
  921. out, _, err = runCommandWithOutput(runCmd)
  922. c.Assert(err, check.IsNil)
  923. id2 := strings.TrimSpace(out)
  924. c.Assert(waitRun(id2), check.IsNil)
  925. links, err := inspectFieldJSON(id2, "HostConfig.Links")
  926. c.Assert(err, check.IsNil)
  927. if links != "[\"/tlink1:/tlink2/tlink1\"]" {
  928. c.Fatal("expected to have links between containers")
  929. }
  930. status, _, err := sockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil)
  931. c.Assert(err, check.IsNil)
  932. c.Assert(status, check.Equals, http.StatusNoContent)
  933. linksPostRm, err := inspectFieldJSON(id2, "HostConfig.Links")
  934. c.Assert(err, check.IsNil)
  935. if linksPostRm != "null" {
  936. c.Fatal("call to api deleteContainer links should have removed the specified links")
  937. }
  938. }
  939. func (s *DockerSuite) TestContainerApiDeleteConflict(c *check.C) {
  940. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
  941. out, _, err := runCommandWithOutput(runCmd)
  942. c.Assert(err, check.IsNil)
  943. id := strings.TrimSpace(out)
  944. c.Assert(waitRun(id), check.IsNil)
  945. status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
  946. c.Assert(status, check.Equals, http.StatusConflict)
  947. c.Assert(err, check.IsNil)
  948. }
  949. func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) {
  950. testRequires(c, SameHostDaemon)
  951. runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/testvolume", "busybox", "top")
  952. out, _, err := runCommandWithOutput(runCmd)
  953. c.Assert(err, check.IsNil)
  954. id := strings.TrimSpace(out)
  955. c.Assert(waitRun(id), check.IsNil)
  956. vol, err := inspectFieldMap(id, "Volumes", "/testvolume")
  957. c.Assert(err, check.IsNil)
  958. _, err = os.Stat(vol)
  959. c.Assert(err, check.IsNil)
  960. status, _, err := sockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil)
  961. c.Assert(status, check.Equals, http.StatusNoContent)
  962. c.Assert(err, check.IsNil)
  963. if _, err := os.Stat(vol); !os.IsNotExist(err) {
  964. c.Fatalf("expected to get ErrNotExist error, got %v", err)
  965. }
  966. }
  967. // Regression test for https://github.com/docker/docker/issues/6231
  968. func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
  969. out, _ := dockerCmd(c, "create", "-v", "/foo", "busybox", "true")
  970. id := strings.TrimSpace(out)
  971. conn, err := sockConn(time.Duration(10 * time.Second))
  972. if err != nil {
  973. c.Fatal(err)
  974. }
  975. client := httputil.NewClientConn(conn, nil)
  976. defer client.Close()
  977. bindCfg := strings.NewReader(`{"Binds": ["/tmp:/foo"]}`)
  978. req, err := http.NewRequest("POST", "/containers/"+id+"/start", bindCfg)
  979. if err != nil {
  980. c.Fatal(err)
  981. }
  982. req.Header.Set("Content-Type", "application/json")
  983. // This is a cheat to make the http request do chunked encoding
  984. // Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite
  985. // https://golang.org/src/pkg/net/http/request.go?s=11980:12172
  986. req.ContentLength = -1
  987. resp, err := client.Do(req)
  988. if err != nil {
  989. c.Fatalf("error starting container with chunked encoding: %v", err)
  990. }
  991. resp.Body.Close()
  992. if resp.StatusCode != 204 {
  993. c.Fatalf("expected status code 204, got %d", resp.StatusCode)
  994. }
  995. out, err = inspectFieldJSON(id, "HostConfig.Binds")
  996. if err != nil {
  997. c.Fatal(err)
  998. }
  999. var binds []string
  1000. if err := json.NewDecoder(strings.NewReader(out)).Decode(&binds); err != nil {
  1001. c.Fatal(err)
  1002. }
  1003. if len(binds) != 1 {
  1004. c.Fatalf("got unexpected binds: %v", binds)
  1005. }
  1006. expected := "/tmp:/foo"
  1007. if binds[0] != expected {
  1008. c.Fatalf("got incorrect bind spec, wanted %s, got: %s", expected, binds[0])
  1009. }
  1010. }