diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 743878be18..575b40db00 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -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 } diff --git a/cli/command/container/run.go b/cli/command/container/run.go index bc1fc929b3..cf49779f78 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -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 diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 16c8c9a877..5a1ec89f5a 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -1994,6 +1994,7 @@ _docker_container_run_and_create() { --oom-kill-disable --privileged --publish-all -P + --quiet -q --read-only --tty -t " diff --git a/contrib/completion/zsh/_docker b/contrib/completion/zsh/_docker index af981246b9..bad961ebbd 100644 --- a/contrib/completion/zsh/_docker +++ b/contrib/completion/zsh/_docker @@ -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 '')]:shm size: " diff --git a/docs/reference/commandline/create.md b/docs/reference/commandline/create.md index 5cdc608651..6b22845659 100644 --- a/docs/reference/commandline/create.md +++ b/docs/reference/commandline/create.md @@ -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 diff --git a/docs/reference/commandline/run.md b/docs/reference/commandline/run.md index c117cdb828..878a39509f 100644 --- a/docs/reference/commandline/run.md +++ b/docs/reference/commandline/run.md @@ -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