浏览代码

Merge pull request #23413 from vdemeester/client-fix-context-sharing

Fix some api/client context sharing/plumbing
Alexander Morozov 9 年之前
父节点
当前提交
5bdc833e44
共有 3 个文件被更改,包括 8 次插入3 次删除
  1. 2 1
      api/client/container/restart.go
  2. 3 1
      api/client/network/inspect.go
  3. 3 1
      api/client/volume/inspect.go

+ 2 - 1
api/client/container/restart.go

@@ -38,9 +38,10 @@ func NewRestartCommand(dockerCli *client.DockerCli) *cobra.Command {
 }
 
 func runRestart(dockerCli *client.DockerCli, opts *restartOptions) error {
+	ctx := context.Background()
 	var errs []string
 	for _, name := range opts.containers {
-		if err := dockerCli.Client().ContainerRestart(context.Background(), name, time.Duration(opts.nSeconds)*time.Second); err != nil {
+		if err := dockerCli.Client().ContainerRestart(ctx, name, time.Duration(opts.nSeconds)*time.Second); err != nil {
 			errs = append(errs, err.Error())
 		} else {
 			fmt.Fprintf(dockerCli.Out(), "%s\n", name)

+ 3 - 1
api/client/network/inspect.go

@@ -35,8 +35,10 @@ func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
 func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
 	client := dockerCli.Client()
 
+	ctx := context.Background()
+
 	getNetFunc := func(name string) (interface{}, []byte, error) {
-		return client.NetworkInspectWithRaw(context.Background(), name)
+		return client.NetworkInspectWithRaw(ctx, name)
 	}
 
 	return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getNetFunc)

+ 3 - 1
api/client/volume/inspect.go

@@ -35,8 +35,10 @@ func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
 func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
 	client := dockerCli.Client()
 
+	ctx := context.Background()
+
 	getVolFunc := func(name string) (interface{}, []byte, error) {
-		i, err := client.VolumeInspect(context.Background(), name)
+		i, err := client.VolumeInspect(ctx, name)
 		return i, nil, err
 	}