...

Source file src/github.com/Microsoft/hcsshim/pkg/go-runhcs/runhcs_list.go

Documentation: github.com/Microsoft/hcsshim/pkg/go-runhcs

     1  //go:build windows
     2  
     3  package runhcs
     4  
     5  import (
     6  	"context"
     7  	"encoding/json"
     8  
     9  	irunhcs "github.com/Microsoft/hcsshim/internal/runhcs"
    10  )
    11  
    12  // ContainerState is the representation of the containers state at the moment of
    13  // query.
    14  type ContainerState = irunhcs.ContainerState
    15  
    16  // List containers started by runhcs.
    17  //
    18  // Note: This is specific to the Runhcs.Root namespace provided in the global
    19  // settings.
    20  func (r *Runhcs) List(context context.Context) ([]*ContainerState, error) {
    21  	data, err := cmdOutput(r.command(context, "list", "--format=json"), false)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  	var out []*ContainerState
    26  	if err := json.Unmarshal(data, &out); err != nil {
    27  		return nil, err
    28  	}
    29  	return out, nil
    30  }
    31  

View as plain text