create/run: remove default --stop-signal

The DefaultStopSignal const has been deprecated, because the daemon already
handles a default value. The current code did not actually send the default
value unless the flag was set, which also made the flag description incorrect,
because in that case, the _daemon's_ default would be used, which could
potentially be different as was specified here.

This patch removes the default value from the flag, leaving it to the daemon
to set a default.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-08-11 11:00:27 +02:00
parent 1fdafcd162
commit 214cd05aa1
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
5 changed files with 15 additions and 14 deletions

View File

@ -20,7 +20,6 @@ import (
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/moby/sys/signal"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -183,7 +182,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
flags.Var(&copts.labelsFile, "label-file", "Read in a line delimited file of labels") flags.Var(&copts.labelsFile, "label-file", "Read in a line delimited file of labels")
flags.BoolVar(&copts.readonlyRootfs, "read-only", false, "Mount the container's root filesystem as read only") flags.BoolVar(&copts.readonlyRootfs, "read-only", false, "Mount the container's root filesystem as read only")
flags.StringVar(&copts.restartPolicy, "restart", "no", "Restart policy to apply when a container exits") flags.StringVar(&copts.restartPolicy, "restart", "no", "Restart policy to apply when a container exits")
flags.StringVar(&copts.stopSignal, "stop-signal", signal.DefaultStopSignal, "Signal to stop a container") flags.StringVar(&copts.stopSignal, "stop-signal", "", "Signal to stop the container")
flags.IntVar(&copts.stopTimeout, "stop-timeout", 0, "Timeout (in seconds) to stop a container") flags.IntVar(&copts.stopTimeout, "stop-timeout", 0, "Timeout (in seconds) to stop a container")
flags.SetAnnotation("stop-timeout", "version", []string{"1.25"}) flags.SetAnnotation("stop-timeout", "version", []string{"1.25"})
flags.Var(copts.sysctls, "sysctl", "Sysctl options") flags.Var(copts.sysctls, "sysctl", "Sysctl options")
@ -599,11 +598,9 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
Entrypoint: entrypoint, Entrypoint: entrypoint,
WorkingDir: copts.workingDir, WorkingDir: copts.workingDir,
Labels: opts.ConvertKVStringsToMap(labels), Labels: opts.ConvertKVStringsToMap(labels),
StopSignal: copts.stopSignal,
Healthcheck: healthConfig, Healthcheck: healthConfig,
} }
if flags.Changed("stop-signal") {
config.StopSignal = copts.stopSignal
}
if flags.Changed("stop-timeout") { if flags.Changed("stop-timeout") {
config.StopTimeout = &copts.stopTimeout config.StopTimeout = &copts.stopTimeout
} }

View File

@ -108,7 +108,7 @@ Options:
The format is `<number><unit>`. `number` must be greater than `0`. The format is `<number><unit>`. `number` must be greater than `0`.
Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes),
or `g` (gigabytes). If you omit the unit, the system uses bytes. or `g` (gigabytes). If you omit the unit, the system uses bytes.
--stop-signal string Signal to stop a container (default "SIGTERM") --stop-signal string Signal to stop the container
--stop-timeout int Timeout (in seconds) to stop a container --stop-timeout int Timeout (in seconds) to stop a container
--storage-opt value Storage driver options for the container (default []) --storage-opt value Storage driver options for the container (default [])
--sysctl value Sysctl options (default map[]) --sysctl value Sysctl options (default map[])

View File

@ -23,10 +23,10 @@ inside the container is sent `SIGKILL` signal (default), or the signal that is
specified with the `--signal` option. You can reference a container by its specified with the `--signal` option. You can reference a container by its
ID, ID-prefix, or name. ID, ID-prefix, or name.
The `--signal` (or `-s` shorthand) flag sets the system call signal that is sent The `--signal` flag sets the system call signal that is sent to the container.
to the container. This signal can be a signal name in the format `SIG<NAME>`, for This signal can be a signal name in the format `SIG<NAME>`, for instance `SIGINT`,
instance `SIGINT`, or an unsigned number that matches a position in the kernel's or an unsigned number that matches a position in the kernel's syscall table,
syscall table, for instance `2`. for instance `2`.
While the default (`SIGKILL`) signal will terminate the container, the signal While the default (`SIGKILL`) signal will terminate the container, the signal
set through `--signal` may be non-terminal, depending on the container's main set through `--signal` may be non-terminal, depending on the container's main

View File

@ -119,7 +119,7 @@ Options:
Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes),
or `g` (gigabytes). If you omit the unit, the system uses bytes. or `g` (gigabytes). If you omit the unit, the system uses bytes.
--sig-proxy Proxy received signals to the process (default true) --sig-proxy Proxy received signals to the process (default true)
--stop-signal string Signal to stop a container (default "SIGTERM") --stop-signal string Signal to stop the container
--stop-timeout int Timeout (in seconds) to stop a container --stop-timeout int Timeout (in seconds) to stop a container
--storage-opt value Storage driver options for the container (default []) --storage-opt value Storage driver options for the container (default [])
--sysctl value Sysctl options (default map[]) --sysctl value Sysctl options (default map[])
@ -752,7 +752,8 @@ container to exit. This signal can be a signal name in the format `SIG<NAME>`,
for instance `SIGKILL`, or an unsigned number that matches a position in the for instance `SIGKILL`, or an unsigned number that matches a position in the
kernel's syscall table, for instance `9`. kernel's syscall table, for instance `9`.
The default is `SIGTERM` if not specified. The default is defined by [`STOPSIGNAL`](https://docs.docker.com/engine/reference/builder/#stopsignal)
in the image, or `SIGTERM` if the image has no `STOPSIGNAL` defined.
### Optional security options (--security-opt) ### Optional security options (--security-opt)

View File

@ -621,14 +621,17 @@ incompatible with any restart policy other than `none`.
For the `overlay2` storage driver, the size option is only available if the backing fs is `xfs` and mounted with the `pquota` mount option. For the `overlay2` storage driver, the size option is only available if the backing fs is `xfs` and mounted with the `pquota` mount option.
Under these conditions, user can pass any size less than the backing fs size. Under these conditions, user can pass any size less than the backing fs size.
**--stop-signal**=*SIGTERM* **--stop-signal**=""
Signal to stop the container. Default is SIGTERM. Signal to stop the container.
The `--stop-signal` flag sets the system call signal that will be sent to the The `--stop-signal` flag sets the system call signal that will be sent to the
container to exit. This signal can be a signal name in the format `SIG<NAME>`, container to exit. This signal can be a signal name in the format `SIG<NAME>`,
for instance `SIGKILL`, or an unsigned number that matches a position in the for instance `SIGKILL`, or an unsigned number that matches a position in the
kernel's syscall table, for instance `9`. kernel's syscall table, for instance `9`.
The default is defined by `STOPSIGNAL` in the image, or `SIGTERM` if the image
has no `STOPSIGNAL` defined.
**--stop-timeout** **--stop-timeout**
Timeout (in seconds) to stop a container, or **-1** to disable timeout. Timeout (in seconds) to stop a container, or **-1** to disable timeout.