Skip to content

Commit

Permalink
API: kill: return 409 on invalid state
Browse files Browse the repository at this point in the history
If the container isn't running, make sure to return 409 as specified in
the Docker API [1] and the Podman reference.

[1] https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerKill

Fixes: containers#19368
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
  • Loading branch information
vrothberg committed Jul 31, 2023
1 parent b6a52f1 commit 0caee06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/api/handlers/compat/containers.go
Expand Up @@ -243,6 +243,11 @@ func KillContainer(w http.ResponseWriter, r *http.Request) {
}

if len(report) > 0 && report[0].Err != nil {
if errors.Is(report[0].Err, define.ErrCtrStateInvalid) ||
errors.Is(report[0].Err, define.ErrCtrStopped) {
utils.Error(w, http.StatusConflict, report[0].Err)
return
}
utils.InternalServerError(w, report[0].Err)
return
}
Expand Down
5 changes: 4 additions & 1 deletion test/apiv2/20-containers.at
Expand Up @@ -32,7 +32,10 @@ t POST "containers/foo/attach?logs=true&stream=false" 200 \
$'\001\031'$mytext
t POST "containers/foo/kill" 204

podman run -v /tmp:/tmp $IMAGE true
podman create --replace --name=foo -v /tmp:/tmp $IMAGE true
# cannot kill non-running container
t POST "containers/foo/kill" 409
t POST "libpod/containers/foo/kill" 409

t GET libpod/containers/json 200 length=0

Expand Down

0 comments on commit 0caee06

Please sign in to comment.