github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/run.go (about) 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.StringFlag{ 39 Name: "pidfd-socket", 40 Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the init process", 41 }, 42 cli.BoolFlag{ 43 Name: "detach, d", 44 Usage: "detach from the container's process", 45 }, 46 cli.BoolFlag{ 47 Name: "keep", 48 Usage: "do not delete the container after it exits", 49 }, 50 cli.StringFlag{ 51 Name: "pid-file", 52 Value: "", 53 Usage: "specify the file to write the process id to", 54 }, 55 cli.BoolFlag{ 56 Name: "no-subreaper", 57 Usage: "disable the use of the subreaper used to reap reparented processes", 58 }, 59 cli.BoolFlag{ 60 Name: "no-pivot", 61 Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk", 62 }, 63 cli.BoolFlag{ 64 Name: "no-new-keyring", 65 Usage: "do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key", 66 }, 67 cli.IntFlag{ 68 Name: "preserve-fds", 69 Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)", 70 }, 71 }, 72 Action: func(context *cli.Context) error { 73 if err := checkArgs(context, 1, exactArgs); err != nil { 74 return err 75 } 76 status, err := startContainer(context, CT_ACT_RUN, nil) 77 if err == nil { 78 // exit with the container's exit status so any external supervisor is 79 // notified of the exit with the correct exit status. 80 os.Exit(status) 81 } 82 return fmt.Errorf("runc run failed: %w", err) 83 }, 84 }