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