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