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