func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) { // TODO Windows CI: Investigate further why this fails on Windows to Windows CI. testRequires(c, DaemonIsLinux) path := "/foo" if daemonPlatform == "windows" { path = `c:\foo` } name := "testing" config := map[string]interface{}{ "Image": "busybox", "Volumes": map[string]struct{}{path: {}}, } status, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) bindPath := testutil.RandomTmpDirPath("test", daemonPlatform) config = map[string]interface{}{ "Binds": []string{bindPath + ":" + path}, } status, _, err = request.SockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusNoContent) pth, err := inspectMountSourceField(name, path) c.Assert(err, checker.IsNil) c.Assert(pth, checker.Equals, bindPath, check.Commentf("expected volume host path to be %s, got %s", bindPath, pth)) }
// Test case for 30027: image size reported as -1 in v1.12 client against v1.13 daemon. // This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix. func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) { status, b, err := request.SockRequest("GET", "/images/json", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) var images []types.ImageSummary err = json.Unmarshal(b, &images) c.Assert(err, checker.IsNil) c.Assert(len(images), checker.Not(checker.Equals), 0) for _, image := range images { c.Assert(image.Size, checker.Not(checker.Equals), int64(-1)) } type v124Image struct { ID string `json:"Id"` ParentID string `json:"ParentId"` RepoTags []string RepoDigests []string Created int64 Size int64 VirtualSize int64 Labels map[string]string } status, b, err = request.SockRequest("GET", "/v1.24/images/json", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) var v124Images []v124Image err = json.Unmarshal(b, &v124Images) c.Assert(err, checker.IsNil) c.Assert(len(v124Images), checker.Not(checker.Equals), 0) for _, image := range v124Images { c.Assert(image.Size, checker.Not(checker.Equals), int64(-1)) } }
func (s *DockerSuite) TestAPICreateWithNotExistImage(c *check.C) { name := "test" config := map[string]interface{}{ "Image": "test456:v1", "Volumes": map[string]struct{}{"/tmp": {}}, } status, body, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusNotFound) expected := "No such image: test456:v1" c.Assert(getErrorMessage(c, body), checker.Contains, expected) config2 := map[string]interface{}{ "Image": "test456", "Volumes": map[string]struct{}{"/tmp": {}}, } status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config2, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusNotFound) expected = "No such image: test456:latest" c.Assert(getErrorMessage(c, body), checker.Equals, expected) config3 := map[string]interface{}{ "Image": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", } status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config3, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusNotFound) expected = "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa" c.Assert(getErrorMessage(c, body), checker.Equals, expected) }
func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *check.C) { // TODO Windows to Windows CI - Port this testRequires(c, DaemonIsLinux) volName := "voltst" volPath := "/tmp" dockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox") name := "TestContainerAPIStartVolumesFrom" config := map[string]interface{}{ "Image": "busybox", "Volumes": map[string]struct{}{volPath: {}}, } status, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) config = map[string]interface{}{ "VolumesFrom": []string{volName}, } status, _, err = request.SockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusNoContent) pth, err := inspectMountSourceField(name, volPath) c.Assert(err, checker.IsNil) pth2, err := inspectMountSourceField(volName, volPath) c.Assert(err, checker.IsNil) c.Assert(pth, checker.Equals, pth2, check.Commentf("expected volume host path to be %s, got %s", pth, pth2)) }
func (s *DockerSuite) TestAPIStatsContainerNotFound(c *check.C) { testRequires(c, DaemonIsLinux) status, _, err := request.SockRequest("GET", "/containers/nonexistent/stats", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusNotFound) status, _, err = request.SockRequest("GET", "/containers/nonexistent/stats?stream=0", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusNotFound) }
func (s *DockerSuite) TestInfoAPI(c *check.C) { endpoint := "/info" status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost()) c.Assert(status, checker.Equals, http.StatusOK) c.Assert(err, checker.IsNil) // always shown fields stringsToCheck := []string{ "ID", "Containers", "ContainersRunning", "ContainersPaused", "ContainersStopped", "Images", "LoggingDriver", "OperatingSystem", "NCPU", "OSType", "Architecture", "MemTotal", "KernelVersion", "Driver", "ServerVersion", "SecurityOptions"} out := string(body) for _, linePrefix := range stringsToCheck { c.Assert(out, checker.Contains, linePrefix) } }
func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) { status, body, err := request.SockRequest("GET", "/containers/doesnotexist/attach/ws", nil, daemonHost()) c.Assert(status, checker.Equals, http.StatusNotFound) c.Assert(err, checker.IsNil) expected := "No such container: doesnotexist" c.Assert(getErrorMessage(c, body), checker.Contains, expected) }
// #20638 func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) { name := "foo" runSleepingContainer(c, "-d", "-t", "--name", name) data := map[string]interface{}{ "cmd": []string{"true"}, "AttachStdin": true, } _, b, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), data, daemonHost()) c.Assert(err, checker.IsNil, check.Commentf(string(b))) createResp := struct { ID string `json:"Id"` }{} c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b))) _, body, err := request.SockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", createResp.ID), strings.NewReader(`{"Detach": true}`), "application/json", daemonHost()) c.Assert(err, checker.IsNil) b, err = testutil.ReadBody(body) comment := check.Commentf("response body: %s", b) c.Assert(err, checker.IsNil, comment) resp, _, err := request.SockRequestRaw("GET", "/_ping", nil, "", daemonHost()) c.Assert(err, checker.IsNil) if resp.StatusCode != http.StatusOK { c.Fatal("daemon is down, it should alive") } }
func getInspectBody(c *check.C, version, id string) []byte { endpoint := fmt.Sprintf("/%s/containers/%s/json", version, id) status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusOK) return body }
func (s *DockerSuite) TestAPIImagesFilter(c *check.C) { name := "utest:tag1" name2 := "utest/docker:tag2" name3 := "utest:5000/docker:tag3" for _, n := range []string{name, name2, name3} { dockerCmd(c, "tag", "busybox", n) } type image types.ImageSummary getImages := func(filter string) []image { v := url.Values{} v.Set("filter", filter) status, b, err := request.SockRequest("GET", "/images/json?"+v.Encode(), nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) var images []image err = json.Unmarshal(b, &images) c.Assert(err, checker.IsNil) return images } //incorrect number of matches returned images := getImages("utest*/*") c.Assert(images[0].RepoTags, checker.HasLen, 2) images = getImages("utest") c.Assert(images[0].RepoTags, checker.HasLen, 1) images = getImages("utest*") c.Assert(images[0].RepoTags, checker.HasLen, 1) images = getImages("*5000*/*") c.Assert(images[0].RepoTags, checker.HasLen, 1) }
func (s *DockerSuite) TestResizeAPIResponse(c *check.C) { out, _ := runSleepingContainer(c, "-d") cleanedContainerID := strings.TrimSpace(out) endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost()) c.Assert(status, check.Equals, http.StatusOK) c.Assert(err, check.IsNil) }
func (s *DockerSuite) TestResizeAPIHeightWidthNoInt(c *check.C) { out, _ := runSleepingContainer(c, "-d") cleanedContainerID := strings.TrimSpace(out) endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar" status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost()) c.Assert(status, check.Equals, http.StatusInternalServerError) c.Assert(err, check.IsNil) }
func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) { testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later runSleepingContainer(c, "--name", "docker-kill-test-api", "-d") dockerCmd(c, "stop", "docker-kill-test-api") status, _, err := request.SockRequest("POST", fmt.Sprintf("/v1.19/containers/%s/kill", "docker-kill-test-api"), nil, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusNoContent) }
func createExec(c *check.C, name string) string { _, b, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}}, daemonHost()) c.Assert(err, checker.IsNil, check.Commentf(string(b))) createResp := struct { ID string `json:"Id"` }{} c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b))) return createResp.ID }
func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) { testRequires(c, DaemonIsLinux) out, _ := dockerCmd(c, "run", "-d", "busybox", "top") cleanedContainerID := strings.TrimSpace(out) endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar" status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusInternalServerError) }
func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *check.C) { name := "logs_test" dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") status, body, err := request.SockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil, daemonHost()) c.Assert(status, checker.Equals, http.StatusBadRequest) c.Assert(err, checker.IsNil) expected := "Bad parameters: you must choose at least one stream" c.Assert(getErrorMessage(c, body), checker.Contains, expected) }
func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *check.C) { name := "test-deprecated-api-124" dockerCmd(c, "create", "--name", name, "busybox") config := map[string]interface{}{ "Binds": []string{"/aa:/bb"}, } status, body, err := request.SockRequest("POST", "/containers/"+name+"/start", config, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusBadRequest) c.Assert(string(body), checker.Contains, "was deprecated since v1.10") }
func (s *DockerSuite) TestGetVersion(c *check.C) { status, body, err := request.SockRequest("GET", "/version", nil, daemonHost()) c.Assert(status, checker.Equals, http.StatusOK) c.Assert(err, checker.IsNil) var v types.Version c.Assert(json.Unmarshal(body, &v), checker.IsNil) c.Assert(v.Version, checker.Equals, dockerversion.Version, check.Commentf("Version mismatch")) }
func getAllNetworks() ([]types.NetworkResource, error) { var networks []types.NetworkResource _, b, err := request.SockRequest("GET", "/networks", nil, daemonHost()) if err != nil { return nil, err } if err := json.Unmarshal(b, &networks); err != nil { return nil, err } return networks, nil }
// Regression test for #9414 func (s *DockerSuite) TestExecAPICreateNoCmd(c *check.C) { name := "exec_test" dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") status, body, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil}, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusInternalServerError) comment := check.Commentf("Expected message when creating exec command with no Cmd specified") c.Assert(getErrorMessage(c, body), checker.Contains, "No exec command specified", comment) }
func getAllVolumes() ([]*types.Volume, error) { var volumes volumetypes.VolumesListOKBody _, b, err := request.SockRequest("GET", "/volumes", nil, daemonHost()) if err != nil { return nil, err } if err := json.Unmarshal(b, &volumes); err != nil { return nil, err } return volumes.Volumes, nil }
func getAllPlugins() (types.PluginsListResponse, error) { var plugins types.PluginsListResponse _, b, err := request.SockRequest("GET", "/plugins", nil, daemonHost()) if err != nil { return nil, err } if err := json.Unmarshal(b, &plugins); err != nil { return nil, err } return plugins, nil }
func (s *DockerSuite) TestInfoAPIVersioned(c *check.C) { testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later endpoint := "/v1.20/info" status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost()) c.Assert(status, checker.Equals, http.StatusOK) c.Assert(err, checker.IsNil) out := string(body) c.Assert(out, checker.Contains, "ExecutionDriver") c.Assert(out, checker.Contains, "not supported") }
func (s *DockerSuite) TestVolumesAPIList(c *check.C) { prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "-v", prefix+"/foo", "busybox") status, b, err := request.SockRequest("GET", "/volumes", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) var volumes volumetypes.VolumesListOKBody c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) }
// Test for #25099 func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) { name := "test1" config := map[string]interface{}{ "Image": "busybox", "Env": []string{"", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, "Cmd": []string{"true"}, } status, body, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusInternalServerError) expected := "invalid environment variable:" c.Assert(getErrorMessage(c, body), checker.Contains, expected) name = "test2" config = map[string]interface{}{ "Image": "busybox", "Env": []string{"=", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, "Cmd": []string{"true"}, } status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusInternalServerError) expected = "invalid environment variable: =" c.Assert(getErrorMessage(c, body), checker.Contains, expected) name = "test3" config = map[string]interface{}{ "Image": "busybox", "Env": []string{"=foo", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, "Cmd": []string{"true"}, } status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusInternalServerError) expected = "invalid environment variable: =foo" c.Assert(getErrorMessage(c, body), checker.Contains, expected) }
func (s *DockerSuite) TestExecAPICreateContainerPaused(c *check.C) { // Not relevant on Windows as Windows containers cannot be paused testRequires(c, DaemonIsLinux) name := "exec_create_test" dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "pause", name) status, body, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}}, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusConflict) comment := check.Commentf("Expected message when creating exec command with Container %s is paused", name) c.Assert(getErrorMessage(c, body), checker.Contains, "Container "+name+" is paused, unpause the container before exec", comment) }
func (s *DockerSuite) TestVolumesAPICreate(c *check.C) { config := volumetypes.VolumesCreateBody{ Name: "test", } status, b, err := request.SockRequest("POST", "/volumes/create", config, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b))) var vol types.Volume err = json.Unmarshal(b, &vol) c.Assert(err, checker.IsNil) c.Assert(filepath.Base(filepath.Dir(vol.Mountpoint)), checker.Equals, config.Name) }
func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) { config := volumetypes.VolumesCreateBody{ Name: "test", } status, b, err := request.SockRequest("POST", "/volumes/create", config, daemonHost()) c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b))) status, b, err = request.SockRequest("GET", "/volumes", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) var volumes volumetypes.VolumesListOKBody c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) var vol types.Volume status, b, err = request.SockRequest("GET", "/volumes/"+config.Name, nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) c.Assert(json.Unmarshal(b, &vol), checker.IsNil) c.Assert(vol.Name, checker.Equals, config.Name) }
func (s *DockerSuite) TestAPIImagesDelete(c *check.C) { if daemonPlatform != "windows" { testRequires(c, Network) } name := "test-api-images-delete" out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) c.Assert(err, checker.IsNil) id := strings.TrimSpace(out) dockerCmd(c, "tag", name, "test:tag1") status, _, err := request.SockRequest("DELETE", "/images/"+id, nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusConflict) status, _, err = request.SockRequest("DELETE", "/images/test:noexist", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image status, _, err = request.SockRequest("DELETE", "/images/test:tag1", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) }
func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) { prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox") status, b, err := request.SockRequest("GET", "/volumes", nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusOK) var volumes volumetypes.VolumesListOKBody c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) v := volumes.Volumes[0] status, _, err = request.SockRequest("DELETE", "/volumes/"+v.Name, nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use")) dockerCmd(c, "rm", "-f", "test") status, data, err := request.SockRequest("DELETE", "/volumes/"+v.Name, nil, daemonHost()) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data))) }