Documentation
¶
Overview ¶
Package docker provides a simple docker abstraction layer.
Please note that the methods are idempotent (i.e. they can be called multiple times without changing the result). This is important because it reduces the need for additional checks if the user runs a command multiple times. E.g. the code that uses this package doesn't need to check if the container already runs, ContainerRuns does that internally and just does nothing if the container is already running.
Additionally it sometimes makes error handling simpler. If an particular method failed halfway, it can just be called again without causing any issues.
The general pattern used internally in this package is:
- Check if the desired result (e.g. container running) already exists
- If yes, do nothing
- If no, invoke the action that produces the result (e.g. run container)
Index ¶
- type BasicManager
- func (bm *BasicManager) AddBasePath(myPath string) string
- func (bm *BasicManager) ContainerAbsent(ctx context.Context, container Container) error
- func (bm *BasicManager) ContainerRuns(ctx context.Context, container Container) error
- func (bm *BasicManager) ContainerStopped(ctx context.Context, container Container) error
- func (bm *BasicManager) DoesNetworkExist(ctx context.Context, networkID string) (bool, error)
- func (bm *BasicManager) IsContainerRunning(ctx context.Context, containerName string) (bool, error)
- func (bm *BasicManager) ListContainerNames(ctx context.Context) ([]string, error)
- func (bm *BasicManager) ListVolumeIDs(ctx context.Context) ([]string, error)
- func (bm *BasicManager) NetworkAbsent(ctx context.Context, networkID string) error
- func (bm *BasicManager) NetworkExists(ctx context.Context, networkID string) error
- func (bm *BasicManager) RunTransientContainer(ctx context.Context, container Container) (string, error)
- func (bm *BasicManager) VolumeAbsent(ctx context.Context, volumeID string) error
- type Container
- type Mount
- type Port
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicManager ¶
type BasicManager struct {
// contains filtered or unexported fields
}
func NewBasicManager ¶
func NewBasicManager(currentNode node.Node) (*BasicManager, error)
NewBasicManager creates a BasicManager
func (*BasicManager) AddBasePath ¶
func (bm *BasicManager) AddBasePath(myPath string) string
AddBasePath adds the base path if the supplied path is relative
func (*BasicManager) ContainerAbsent ¶
func (bm *BasicManager) ContainerAbsent(ctx context.Context, container Container) error
ContainerAbsent stops and removes a container if it is running/exists
func (*BasicManager) ContainerRuns ¶
func (bm *BasicManager) ContainerRuns(ctx context.Context, container Container) error
ContainerRuns creates and starts a container if it doesn't exist/run yet
func (*BasicManager) ContainerStopped ¶
func (bm *BasicManager) ContainerStopped(ctx context.Context, container Container) error
ContainerStopped stops a container if it is running
func (*BasicManager) DoesNetworkExist ¶
DoesNetworkExist returns true if the docker network exists
func (*BasicManager) IsContainerRunning ¶
func (*BasicManager) ListContainerNames ¶
func (bm *BasicManager) ListContainerNames(ctx context.Context) ([]string, error)
ListContainerNames lists all containers by name
func (*BasicManager) ListVolumeIDs ¶
func (bm *BasicManager) ListVolumeIDs(ctx context.Context) ([]string, error)
ListVolumeIDs lists all volumes by name (which is also a unique id)
func (*BasicManager) NetworkAbsent ¶
func (bm *BasicManager) NetworkAbsent(ctx context.Context, networkID string) error
NetworkAbsent removes a network if it exists
func (*BasicManager) NetworkExists ¶
func (bm *BasicManager) NetworkExists(ctx context.Context, networkID string) error
NetworkExists creates a network if it doesn't exist yet
func (*BasicManager) RunTransientContainer ¶
func (bm *BasicManager) RunTransientContainer(ctx context.Context, container Container) (string, error)
RunTransientContainer runs a container once and removes it after it is finished.
func (*BasicManager) VolumeAbsent ¶
func (bm *BasicManager) VolumeAbsent(ctx context.Context, volumeID string) error
VolumeAbsent removes a network if it exists
type Container ¶
type Container struct { Name string Image string EnvFilename string Mounts []Mount Ports []Port Cmd []string CmdFile string User string CollectLogs bool }
Container defines all parameters used to create a container