1
0
Эх сурвалжийг харах

Merge pull request #833 from docker/add-run-rm

Add --rm to run command (as not yet implemented)
Guillaume Tardif 5 жил өмнө
parent
commit
56b4c772a2

+ 10 - 2
cli/cmd/run/run.go

@@ -18,6 +18,7 @@ package run
 
 import (
 	"context"
+	"errors"
 	"fmt"
 	"io"
 	"os"
@@ -43,7 +44,7 @@ func Command(contextType string) *cobra.Command {
 			if len(args) > 1 {
 				opts.Command = args[1:]
 			}
-			return runRun(cmd.Context(), args[0], opts)
+			return runRun(cmd.Context(), args[0], contextType, opts)
 		},
 	}
 	cmd.Flags().SetInterspersed(false)
@@ -58,15 +59,22 @@ func Command(contextType string) *cobra.Command {
 	cmd.Flags().StringArrayVarP(&opts.Environment, "env", "e", []string{}, "Set environment variables")
 	cmd.Flags().StringArrayVar(&opts.EnvironmentFiles, "env-file", []string{}, "Path to environment files to be translated as environment variables")
 	cmd.Flags().StringVarP(&opts.RestartPolicyCondition, "restart", "", containers.RestartPolicyNone, "Restart policy to apply when a container exits")
+	cmd.Flags().BoolVar(&opts.Rm, "rm", false, "Automatically remove the container when it exits")
 
 	if contextType == store.AciContextType {
 		cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
 	}
 
+	_ = cmd.Flags().MarkHidden("rm")
+
 	return cmd
 }
 
-func runRun(ctx context.Context, image string, opts run.Opts) error {
+func runRun(ctx context.Context, image string, contextType string, opts run.Opts) error {
+	if opts.Rm {
+		return errors.New(`Option "rm" is not yet implemented for context type: ` + contextType)
+	}
+
 	c, err := client.New(ctx)
 	if err != nil {
 		return err

+ 1 - 0
cli/options/run/opts.go

@@ -46,6 +46,7 @@ type Opts struct {
 	EnvironmentFiles       []string
 	RestartPolicyCondition string
 	DomainName             string
+	Rm                     bool
 }
 
 // ToContainerConfig convert run options to a container configuration