Skip to content

docker-py does not honor Config->StopTimeout value when stopping container #1815

@Anvil

Description

@Anvil

By enforcing its own "t" default value on "POST /<version>/containers/<id>/stop" requests, docker-py overrides the container Config->StopTimeout implemented in moby/moby#22566 and documented in https://docs.docker.com/engine/reference/commandline/create/#options.

The docker command line client honors StopTimeout value and does not transmit any t value, unless the user provides a --time option. I think docker-py should be consistent with that behaviour.

I've managed to reproduced this with an ubuntu image with this script (named /stoptimeout) inside the image:

#!/bin/bash
handler() {
    local -i i=0
    while sleep 1; do
	printf 'Counting: %d\n' $((++i))
    done
}
trap handler TERM
sleep 1d &
while ! wait ; do : ; done

then in one shell:

docker run -ti --rm --name stoptimeout_test --stop-timeout=5 my-image /stoptimeout

In a second shell run

docker stop stoptimeout_test

The docker run shell should print:

$ docker run -ti --stop-timeout=5 my-image /stoptimeout
Counting: 1
Counting: 2
Counting: 3
Counting: 4
zsh: exit 137

Repeat operations, but instead of docker stop, use docker-py:

import docker
docker.APIClient().stop("stoptimeout_test")

The docker run shell should print:

[dnade@dnade-2 ~]# docker run -ti --stop-timeout=5 my-image /stoptimeout
Counting: 1
Counting: 2
Counting: 3
Counting: 4
Counting: 5
Counting: 6
Counting: 7
Counting: 8
Counting: 9
zsh: exit 137

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions