...

Source file src/github.com/Microsoft/hcsshim/cmd/runhcs/run.go

Documentation: github.com/Microsoft/hcsshim/cmd/runhcs

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/appargs"
    10  	"github.com/urfave/cli"
    11  )
    12  
    13  // default action is to start a container
    14  var runCommand = cli.Command{
    15  	Name:  "run",
    16  	Usage: "create and run a container",
    17  	ArgsUsage: `<container-id>
    18  
    19  Where "<container-id>" is your name for the instance of the container that you
    20  are starting. The name you provide for the container instance must be unique on
    21  your host.`,
    22  	Description: `The run command creates an instance of a container for a bundle. The bundle
    23  is a directory with a specification file named "` + specConfig + `" and a root
    24  filesystem.
    25  
    26  The specification file includes an args parameter. The args parameter is used
    27  to specify command(s) that get run when the container is started. To change the
    28  command(s) that get executed on start, edit the args parameter of the spec.`,
    29  	Flags: append(createRunFlags,
    30  		cli.BoolFlag{
    31  			Name:  "detach, d",
    32  			Usage: "detach from the container's process",
    33  		},
    34  	),
    35  	Before: appargs.Validate(argID),
    36  	Action: func(context *cli.Context) error {
    37  		cfg, err := containerConfigFromContext(context)
    38  		if err != nil {
    39  			return err
    40  		}
    41  		c, err := createContainer(cfg)
    42  		if err != nil {
    43  			return err
    44  		}
    45  		if err != nil {
    46  			return err
    47  		}
    48  		p, err := os.FindProcess(c.ShimPid)
    49  		if err != nil {
    50  			return err
    51  		}
    52  		err = c.Exec()
    53  		if err != nil {
    54  			return err
    55  		}
    56  		if !context.Bool("detach") {
    57  			state, err := p.Wait()
    58  			if err != nil {
    59  				return err
    60  			}
    61  			_ = c.Remove()
    62  			os.Exit(int(state.Sys().(syscall.WaitStatus).ExitCode))
    63  		}
    64  		return nil
    65  	},
    66  }
    67  

View as plain text