github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/run.go (about)

     1  // +build linux
     2  
     3  package main
     4  
     5  import (
     6  	"os"
     7  
     8  	"github.com/urfave/cli"
     9  )
    10  
    11  // default action is to start a container
    12  var runCommand = cli.Command{
    13  	Name:  "run",
    14  	Usage: "create and run a container",
    15  	ArgsUsage: `<container-id>
    16  
    17  Where "<container-id>" is your name for the instance of the container that you
    18  are starting. The name you provide for the container instance must be unique on
    19  your host.`,
    20  	Description: `The run command creates an instance of a container for a bundle. The bundle
    21  is a directory with a specification file named "` + specConfig + `" and a root
    22  filesystem.
    23  
    24  The specification file includes an args parameter. The args parameter is used
    25  to specify command(s) that get run when the container is started. To change the
    26  command(s) that get executed on start, edit the args parameter of the spec. See
    27  "runc spec --help" for more explanation.`,
    28  	Flags: []cli.Flag{
    29  		cli.StringFlag{
    30  			Name:  "bundle, b",
    31  			Value: "",
    32  			Usage: `path to the root of the bundle directory, defaults to the current directory`,
    33  		},
    34  		cli.StringFlag{
    35  			Name:  "console",
    36  			Value: "",
    37  			Usage: "specify the pty slave path for use with the container",
    38  		},
    39  		cli.BoolFlag{
    40  			Name:  "detach, d",
    41  			Usage: "detach from the container's process",
    42  		},
    43  		cli.StringFlag{
    44  			Name:  "pid-file",
    45  			Value: "",
    46  			Usage: "specify the file to write the process id to",
    47  		},
    48  		cli.BoolFlag{
    49  			Name:  "no-subreaper",
    50  			Usage: "disable the use of the subreaper used to reap reparented processes",
    51  		},
    52  		cli.BoolFlag{
    53  			Name:  "no-pivot",
    54  			Usage: "do not use pivot root to jail process inside rootfs.  This should be used whenever the rootfs is on top of a ramdisk",
    55  		},
    56  		cli.BoolFlag{
    57  			Name:  "no-new-keyring",
    58  			Usage: "do not create a new session keyring for the container.  This will cause the container to inherit the calling processes session key",
    59  		},
    60  	},
    61  	Action: func(context *cli.Context) error {
    62  		spec, err := setupSpec(context)
    63  		if err != nil {
    64  			return err
    65  		}
    66  		status, err := startContainer(context, spec, false)
    67  		if err == nil {
    68  			// exit with the container's exit status so any external supervisor is
    69  			// notified of the exit with the correct exit status.
    70  			os.Exit(status)
    71  		}
    72  		return err
    73  	},
    74  }