...

Source file src/github.com/opencontainers/runc/run.go

Documentation: github.com/opencontainers/runc

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

View as plain text