...

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

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

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"errors"
     7  	"fmt"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/appargs"
    10  	"github.com/urfave/cli"
    11  )
    12  
    13  var startCommand = cli.Command{
    14  	Name:  "start",
    15  	Usage: "executes the user defined process in a created container",
    16  	ArgsUsage: `<container-id>
    17  
    18  Where "<container-id>" is your name for the instance of the container that you
    19  are starting. The name you provide for the container instance must be unique on
    20  your host.`,
    21  	Description: `The start command executes the user defined process in a created container.`,
    22  	Before:      appargs.Validate(argID),
    23  	Action: func(context *cli.Context) error {
    24  		id := context.Args().First()
    25  		container, err := getContainer(id, false)
    26  		if err != nil {
    27  			return err
    28  		}
    29  		defer container.Close()
    30  		status, err := container.Status()
    31  		if err != nil {
    32  			return err
    33  		}
    34  		switch status {
    35  		case containerCreated:
    36  			return container.Exec()
    37  		case containerStopped:
    38  			return errors.New("cannot start a container that has stopped")
    39  		case containerRunning:
    40  			return errors.New("cannot start an already running container")
    41  		default:
    42  			return fmt.Errorf("cannot start a container in the '%s' state", status)
    43  		}
    44  	},
    45  }
    46  

View as plain text