diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index c3074aa3a0..dbaa43da63 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -336,12 +336,16 @@ func (s *containerRouter) postContainersWait(ctx context.Context, w http.Respons if err := httputils.ParseForm(r); err != nil { return err } - switch container.WaitCondition(r.Form.Get("condition")) { - case container.WaitConditionNextExit: - waitCondition = containerpkg.WaitConditionNextExit - case container.WaitConditionRemoved: - waitCondition = containerpkg.WaitConditionRemoved - legacyRemovalWaitPre134 = versions.LessThan(version, "1.34") + if v := r.Form.Get("condition"); v != "" { + switch container.WaitCondition(v) { + case container.WaitConditionNextExit: + waitCondition = containerpkg.WaitConditionNextExit + case container.WaitConditionRemoved: + waitCondition = containerpkg.WaitConditionRemoved + legacyRemovalWaitPre134 = versions.LessThan(version, "1.34") + default: + return errdefs.InvalidParameter(errors.Errorf("invalid condition: %q", v)) + } } } diff --git a/api/swagger.yaml b/api/swagger.yaml index 46505d06c0..49dda13769 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -7018,6 +7018,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -7038,9 +7042,14 @@ paths: - name: "condition" in: "query" description: | - Wait until a container state reaches the given condition, either - 'not-running' (default), 'next-exit', or 'removed'. + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/client/container_wait.go b/client/container_wait.go index 6ab8c1da96..e9b134c9d2 100644 --- a/client/container_wait.go +++ b/client/container_wait.go @@ -33,7 +33,9 @@ func (cli *Client) ContainerWait(ctx context.Context, containerID string, condit errC := make(chan error, 1) query := url.Values{} - query.Set("condition", string(condition)) + if condition != "" { + query.Set("condition", string(condition)) + } resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", query, nil, nil) if err != nil { diff --git a/docs/api/v1.30.yaml b/docs/api/v1.30.yaml index 27e37c690f..925fce5229 100644 --- a/docs/api/v1.30.yaml +++ b/docs/api/v1.30.yaml @@ -4389,6 +4389,10 @@ paths: description: "Exit code of the container" type: "integer" x-nullable: false + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -4408,8 +4412,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.31.yaml b/docs/api/v1.31.yaml index b2e50e3bd1..152e4a9f25 100644 --- a/docs/api/v1.31.yaml +++ b/docs/api/v1.31.yaml @@ -4459,6 +4459,10 @@ paths: description: "Exit code of the container" type: "integer" x-nullable: false + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -4478,8 +4482,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.32.yaml b/docs/api/v1.32.yaml index e6d5d62a86..914928e04f 100644 --- a/docs/api/v1.32.yaml +++ b/docs/api/v1.32.yaml @@ -5696,6 +5696,10 @@ paths: description: "Exit code of the container" type: "integer" x-nullable: false + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5715,8 +5719,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.33.yaml b/docs/api/v1.33.yaml index e6c671660a..0e98c983ad 100644 --- a/docs/api/v1.33.yaml +++ b/docs/api/v1.33.yaml @@ -5701,6 +5701,10 @@ paths: description: "Exit code of the container" type: "integer" x-nullable: false + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5720,8 +5724,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.34.yaml b/docs/api/v1.34.yaml index ebea935440..06f6bc192e 100644 --- a/docs/api/v1.34.yaml +++ b/docs/api/v1.34.yaml @@ -5737,6 +5737,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5756,8 +5760,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.35.yaml b/docs/api/v1.35.yaml index 1193b267a1..eb0905e276 100644 --- a/docs/api/v1.35.yaml +++ b/docs/api/v1.35.yaml @@ -5724,6 +5724,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5743,8 +5747,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.36.yaml b/docs/api/v1.36.yaml index 1f6350ffc8..c1b42aeecc 100644 --- a/docs/api/v1.36.yaml +++ b/docs/api/v1.36.yaml @@ -5748,6 +5748,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5767,8 +5771,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.37.yaml b/docs/api/v1.37.yaml index fbfd1a3d36..910e283319 100644 --- a/docs/api/v1.37.yaml +++ b/docs/api/v1.37.yaml @@ -5775,6 +5775,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5794,8 +5798,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.38.yaml b/docs/api/v1.38.yaml index 40661c0da4..96fff9027b 100644 --- a/docs/api/v1.38.yaml +++ b/docs/api/v1.38.yaml @@ -5836,6 +5836,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -5855,8 +5859,15 @@ paths: type: "string" - name: "condition" in: "query" - description: "Wait until a container state reaches the given condition, either 'not-running' (default), 'next-exit', or 'removed'." + description: | + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.39.yaml b/docs/api/v1.39.yaml index 318c780c81..45b72a8df3 100644 --- a/docs/api/v1.39.yaml +++ b/docs/api/v1.39.yaml @@ -6552,6 +6552,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -6572,9 +6576,14 @@ paths: - name: "condition" in: "query" description: | - Wait until a container state reaches the given condition, either - 'not-running' (default), 'next-exit', or 'removed'. + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.40.yaml b/docs/api/v1.40.yaml index 8e7ddda128..a688b5efa3 100644 --- a/docs/api/v1.40.yaml +++ b/docs/api/v1.40.yaml @@ -6850,6 +6850,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -6870,9 +6874,14 @@ paths: - name: "condition" in: "query" description: | - Wait until a container state reaches the given condition, either - 'not-running' (default), 'next-exit', or 'removed'. + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/v1.41.yaml b/docs/api/v1.41.yaml index 566999c5df..12c5624396 100644 --- a/docs/api/v1.41.yaml +++ b/docs/api/v1.41.yaml @@ -7018,6 +7018,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: @@ -7038,9 +7042,14 @@ paths: - name: "condition" in: "query" description: | - Wait until a container state reaches the given condition, either - 'not-running' (default), 'next-exit', or 'removed'. + Wait until a container state reaches the given condition. + + Defaults to `not-running` if omitted or empty. type: "string" + enum: + - "not-running" + - "next-exit" + - "removed" default: "not-running" tags: ["Container"] /containers/{id}: diff --git a/docs/api/version-history.md b/docs/api/version-history.md index d6e44c4bbc..0a8041812a 100644 --- a/docs/api/version-history.md +++ b/docs/api/version-history.md @@ -40,6 +40,8 @@ keywords: "API, Docker, rcli, REST, documentation" was used and the architecture was ignored. If no `platform` option is set, the host's operating system and architecture as used as default. This change is not versioned, and affects all API versions if the daemon has this patch. +* The `POST /containers/{id}/wait` endpoint now returns a `400` status code if an + invalid `condition` is provided (on API 1.30 and up). ## v1.41 API changes