diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 02ff715259..d2ca58739f 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -157,6 +157,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio } ctx, cancelFun := context.WithCancel(context.Background()) + defer cancelFun() createResponse, err := createContainer(ctx, dockerCli, containerConfig, &opts.createOptions) if err != nil { diff --git a/cli/command/container/start.go b/cli/command/container/start.go index 2617e489f5..243097c0cd 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -55,6 +55,7 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command { // nolint: gocyclo func runStart(dockerCli command.Cli, opts *startOptions) error { ctx, cancelFun := context.WithCancel(context.Background()) + defer cancelFun() if opts.attach || opts.openStdin { // We're going to attach to a container.