cli/command: Add quiet option for create and run
Signed-off-by: Chee Hau Lim <cheehau.lim@mobimeo.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Родитель
7dcd85007b
Коммит
1d4431c1e7
|
@ -36,7 +36,8 @@ type createOptions struct {
|
|||
name string
|
||||
platform string
|
||||
untrusted bool
|
||||
pull string // alway, missing, never
|
||||
pull string // always, missing, never
|
||||
quiet bool
|
||||
}
|
||||
|
||||
// NewCreateCommand creates a new cobra.Command for `docker create`
|
||||
|
@ -63,6 +64,7 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
|
|||
flags.StringVar(&opts.name, "name", "", "Assign a name to the container")
|
||||
flags.StringVar(&opts.pull, "pull", PullImageMissing,
|
||||
`Pull image before creating ("`+PullImageAlways+`"|"`+PullImageMissing+`"|"`+PullImageNever+`")`)
|
||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress the pull output")
|
||||
|
||||
// Add an explicit help that doesn't have a `-h` to prevent the conflict
|
||||
// with hostname
|
||||
|
@ -227,7 +229,11 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
|
|||
}
|
||||
|
||||
pullAndTagImage := func() error {
|
||||
if err := pullImage(ctx, dockerCli, config.Image, opts.platform, stderr); err != nil {
|
||||
pullOut := stderr
|
||||
if opts.quiet {
|
||||
pullOut = io.Discard
|
||||
}
|
||||
if err := pullImage(ctx, dockerCli, config.Image, opts.platform, pullOut); err != nil {
|
||||
return err
|
||||
}
|
||||
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
|
||||
|
@ -259,8 +265,11 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
|
|||
if err != nil {
|
||||
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
|
||||
if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
|
||||
// we don't want to write to stdout anything apart from container.ID
|
||||
fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
|
||||
if !opts.quiet {
|
||||
// we don't want to write to stdout anything apart from container.ID
|
||||
fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
|
||||
}
|
||||
|
||||
if err := pullAndTagImage(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
|
|||
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")
|
||||
flags.StringVar(&opts.createOptions.pull, "pull", PullImageMissing,
|
||||
`Pull image before running ("`+PullImageAlways+`"|"`+PullImageMissing+`"|"`+PullImageNever+`")`)
|
||||
flags.BoolVarP(&opts.createOptions.quiet, "quiet", "q", false, "Suppress the pull output")
|
||||
|
||||
// Add an explicit help that doesn't have a `-h` to prevent the conflict
|
||||
// with hostname
|
||||
|
|
|
@ -1994,6 +1994,7 @@ _docker_container_run_and_create() {
|
|||
--oom-kill-disable
|
||||
--privileged
|
||||
--publish-all -P
|
||||
--quiet -q
|
||||
--read-only
|
||||
--tty -t
|
||||
"
|
||||
|
|
|
@ -650,6 +650,7 @@ __docker_container_subcommand() {
|
|||
"($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports"
|
||||
"($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid"
|
||||
"($help)--privileged[Give extended privileges to this container]"
|
||||
"($help -q --quiet)"{-q,--quiet}"[Suppress the pull output]"
|
||||
"($help)--read-only[Mount the container's root filesystem as read only]"
|
||||
"($help)*--security-opt=[Security options]:security option: "
|
||||
"($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: "
|
||||
|
|
|
@ -99,6 +99,7 @@ Options:
|
|||
-p, --publish value Publish a container's port(s) to the host (default [])
|
||||
-P, --publish-all Publish all exposed ports to random ports
|
||||
--pull string Pull image before creating ("always"|"missing"|"never") (default "missing")
|
||||
-q, --quiet Suppress the pull output
|
||||
--read-only Mount the container's root filesystem as read only
|
||||
--restart string Restart policy to apply when a container exits (default "no")
|
||||
Possible values are: no, on-failure[:max-retry], always, unless-stopped
|
||||
|
|
|
@ -109,6 +109,7 @@ Options:
|
|||
-p, --publish value Publish a container's port(s) to the host (default [])
|
||||
-P, --publish-all Publish all exposed ports to random ports
|
||||
--pull string Pull image before running ("always"|"missing"|"never") (default "missing")
|
||||
-q, --quiet Suppress the pull output
|
||||
--read-only Mount the container's root filesystem as read only
|
||||
--restart string Restart policy to apply when a container exits (default "no")
|
||||
Possible values are : no, on-failure[:max-retry], always, unless-stopped
|
||||
|
|
Загрузка…
Ссылка в новой задаче