diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index c81a9788d6..2a3fd8a091 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -32,7 +32,7 @@ type copyBackend interface { // stateBackend includes functions to implement to provide container state lifecycle functionality. type stateBackend interface { - ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) + ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error) ContainerKill(name string, sig uint64) error ContainerPause(name string) error ContainerRename(oldName, newName string) error diff --git a/api/swagger.yaml b/api/swagger.yaml index 9da6019657..9d106b9dbf 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -2393,7 +2393,7 @@ paths: /containers/create: post: summary: "Create a container" - operationId: "PostContainerCreate" + operationId: "ContainerCreate" consumes: - "application/json" - "application/octet-stream" @@ -2542,15 +2542,19 @@ paths: required: true responses: 201: - description: "no error" + description: "Container created successfully" schema: type: "object" + required: [Id, Warnings] properties: Id: description: "The ID of the created container" type: "string" + x-nullable: false Warnings: + description: "Warnings encountered when creating the container" type: "array" + x-nullable: false items: type: "string" examples: diff --git a/api/types/container/container_create.go b/api/types/container/container_create.go new file mode 100644 index 0000000000..d028e3b121 --- /dev/null +++ b/api/types/container/container_create.go @@ -0,0 +1,21 @@ +package container + +// ---------------------------------------------------------------------------- +// DO NOT EDIT THIS FILE +// This file was generated by `swagger generate operation` +// +// See hack/swagger-gen.sh +// ---------------------------------------------------------------------------- + +// ContainerCreateCreatedBody container create created body +// swagger:model ContainerCreateCreatedBody +type ContainerCreateCreatedBody struct { + + // The ID of the created container + // Required: true + ID string `json:"Id"` + + // Warnings encountered when creating the container + // Required: true + Warnings []string `json:"Warnings"` +} diff --git a/api/types/types.go b/api/types/types.go index 151e355cbe..e06dcc853b 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -13,16 +13,6 @@ import ( "github.com/docker/go-connections/nat" ) -// ContainerCreateResponse contains the information returned to a client on the -// creation of a new container. -type ContainerCreateResponse struct { - // ID is the ID of the created container. - ID string `json:"Id"` - - // Warnings are any warnings encountered during the creation of the container. - Warnings []string `json:"Warnings"` -} - // ContainerExecCreateResponse contains response of Remote API: // POST "/containers/{name:.*}/exec" type ContainerExecCreateResponse struct { diff --git a/builder/builder.go b/builder/builder.go index 0ed052731d..4aed1cb575 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -116,7 +116,7 @@ type Backend interface { // ContainerAttachRaw attaches to container. ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error // ContainerCreate creates a new Docker container and returns potential warnings - ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) + ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error) // ContainerRm removes a container specified by `id`. ContainerRm(name string, config *types.ContainerRmConfig) error // Commit creates a new Docker image from an existing Docker container. diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 7bd3856971..7dc644d28c 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -148,7 +148,7 @@ func newCIDFile(path string) (*cidFile, error) { return &cidFile{path: path, file: f}, nil } -func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*types.ContainerCreateResponse, error) { +func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*container.ContainerCreateCreatedBody, error) { stderr := dockerCli.Err() var containerIDFile *cidFile diff --git a/client/container_create.go b/client/container_create.go index a862172956..c042b17468 100644 --- a/client/container_create.go +++ b/client/container_create.go @@ -5,7 +5,6 @@ import ( "net/url" "strings" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "golang.org/x/net/context" @@ -19,8 +18,8 @@ type configWrapper struct { // ContainerCreate creates a new container based in the given configuration. // It can be associated with a name, but it's not mandatory. -func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) { - var response types.ContainerCreateResponse +func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) { + var response container.ContainerCreateCreatedBody query := url.Values{} if containerName != "" { query.Set("name", containerName) diff --git a/client/container_create_test.go b/client/container_create_test.go index 5325156beb..89641038f7 100644 --- a/client/container_create_test.go +++ b/client/container_create_test.go @@ -9,7 +9,6 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "golang.org/x/net/context" ) @@ -54,7 +53,7 @@ func TestContainerCreateWithName(t *testing.T) { if name != "container_name" { return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name) } - b, err := json.Marshal(types.ContainerCreateResponse{ + b, err := json.Marshal(container.ContainerCreateCreatedBody{ ID: "container_id", }) if err != nil { diff --git a/client/interface.go b/client/interface.go index 1f20a8be73..8f8bbaf55f 100644 --- a/client/interface.go +++ b/client/interface.go @@ -34,7 +34,7 @@ type CommonAPIClient interface { type ContainerAPIClient interface { ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) - ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error) + ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error) diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index 2f91e78784..c34c2076e0 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -23,7 +23,7 @@ type Backend interface { FindNetwork(idName string) (libnetwork.Network, error) SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) + CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateResponse, error) ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error ContainerStop(name string, seconds *int) error ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index 7b6d1069ef..bd5745cc5b 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -12,6 +12,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/versions" executorpkg "github.com/docker/docker/daemon/cluster/executor" @@ -187,7 +188,7 @@ func (c *containerAdapter) waitForDetach(ctx context.Context) error { } func (c *containerAdapter) create(ctx context.Context) error { - var cr types.ContainerCreateResponse + var cr containertypes.ContainerCreateCreatedBody var err error version := httputils.VersionFromContext(ctx) validateHostname := versions.GreaterThanOrEqualTo(version, "1.24") diff --git a/daemon/create.go b/daemon/create.go index bbb1cbc8ad..4ec17c486b 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -22,29 +22,29 @@ import ( ) // CreateManagedContainer creates a container that is managed by a Service -func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) { +func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) { return daemon.containerCreate(params, true, validateHostname) } // ContainerCreate creates a regular container -func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) { +func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) { return daemon.containerCreate(params, false, validateHostname) } -func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (types.ContainerCreateResponse, error) { +func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) { start := time.Now() if params.Config == nil { - return types.ContainerCreateResponse{}, fmt.Errorf("Config cannot be empty in order to create a container") + return containertypes.ContainerCreateCreatedBody{}, fmt.Errorf("Config cannot be empty in order to create a container") } warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, err + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err } err = daemon.verifyNetworkingConfig(params.NetworkingConfig) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, err + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err } if params.HostConfig == nil { @@ -52,15 +52,16 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage } err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, err + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err } container, err := daemon.create(params, managed) if err != nil { - return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err) + return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, daemon.imageNotExistToErrcode(err) } containerActions.WithValues("create").UpdateSince(start) - return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil + + return containertypes.ContainerCreateCreatedBody{ID: container.ID, Warnings: warnings}, nil } // Create creates a new container from the given configuration with a given name. diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index c30197f435..a5c02b10bc 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -13,4 +13,5 @@ swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ -n VolumesList \ - -n VolumesCreate + -n VolumesCreate \ + -n ContainerCreate diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 97ae216378..e4415a81be 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -574,7 +574,7 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -597,7 +597,7 @@ func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -632,7 +632,7 @@ func UtilCreateNetworkMode(c *check.C, networkMode string) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -657,7 +657,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), checker.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1349,7 +1349,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check. c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1381,7 +1381,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) { c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1413,7 +1413,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) { c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) @@ -1443,7 +1443,7 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted( c.Assert(err, check.IsNil) c.Assert(status, check.Equals, http.StatusCreated) - var container types.ContainerCreateResponse + var container containertypes.ContainerCreateCreatedBody c.Assert(json.Unmarshal(body, &container), check.IsNil) status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)