docker

package module
v2.0.0-beta1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 17 Imported by: 4

README

Docker sdk wrapper

This package provides a wrapper for the docker sdk, creating and running commands in containers.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorContainerExitedWithNonZeroCode = errors.New("exited with non 0 code")
	ErrorContainerDead                  = errors.New("container died")
	ErrorContainerStartTimeout          = errors.New("timed out waiting for the container to start")
)
View Source
var (
	ErrorClientNotSet = errors.New("client not set")
	ErrorEmptyCommand = errors.New("container command cannot be empty")
)
View Source
var ErrorImageDoesNotExist = errors.New("no such image")

ErrorImageDoesNotExist returned when inspecting an image that does not exist on the system.

View Source
var (
	// StdIOStream is the standard ioStream, most people will just use this.
	StdIOStream = IOStream{
		In:  os.Stdin,
		Out: os.Stdout,
		Err: os.Stderr,
	}
)

Functions

func SetClient

func SetClient(c client.APIClient)

SetClient allows to set the docker client. Default a new client will be started with client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())

Types

type Command

type Command []string

func (Command) String

func (c Command) String() string

type Container

type Container interface {
	HasIOStream
	// ID the id of the container.
	ID() string
	// Create the container, call Start to start it.
	Create(ctx context.Context) error
	// Start the container.
	Start(ctx context.Context, timeout time.Duration) error
	// Stop sends SIGINT to the container.
	Stop(ctx context.Context) error
	// Kill sends SIGKILL to the container.
	Kill(ctx context.Context) error
	// Wait for the container to stop running, see dockercontainer.WaitCondition.
	Wait(ctx context.Context) error
	// Remove the container.
	Remove(ctx context.Context) error
	// Exec execute a Command in the running container.
	Exec(ctx context.Context, cfg ExecConfig) (Exec, error)
	// AttachIO attach the I/O streams from the running command of the container to the Wrapper streams.
	AttachIO(ctx context.Context) (IOStreamer, error)
	// Inspect the container.
	Inspect(ctx context.Context) (types.ContainerJSON, error)
	// Resize the container
	Resize(ctx context.Context, width uint, height uint)
}

Container represents a docker container.

func FindContainerByName

func FindContainerByName(ctx context.Context, name string) (Container, error)

FindContainerByName tries to find an existing container with the same name in the docker daemon.

func NewContainer

func NewContainer(cfg ContainerConfig) (Container, error)

type ContainerConfig

type ContainerConfig struct {
	Image       string            // Image Required
	Enviroment  map[string]string // Enviroment container's enviroment name:value
	Labels      map[string]string // Labels container's labels name:value
	Directories map[string]string // Directories to mount to container src:target
	WorkingDir  string            // WorkingDir the work directory of the container. Required
	Name        string            // Name is the container name, defaults to randomly generated
	IOStream    IOStream          // IOStream the input/output streams
	Command     Command           // Command the command to start the container with
	AutoRemove  bool              // AutoRemove automatically remove the container when it exits
	TTY         bool              // TTY enable tty on the container
}

ContainerConfig contains the configuration data about a container.

type ContainerStatus

type ContainerStatus string
const (
	ContainerStatusCreated    ContainerStatus = "created"
	ContainerStatusRunning    ContainerStatus = "running"
	ContainerStatusPaused     ContainerStatus = "paused"
	ContainerStatusRestarting ContainerStatus = "restarting"
	ContainerStatusRemoving   ContainerStatus = "removing"
	ContainerStatusExited     ContainerStatus = "exited"
	ContainerStatusDead       ContainerStatus = "dead"
)

type Exec

type Exec interface {
	HasIOStream
	// ID the Exec id.
	ID() string
	// Start the Exec.
	Start(ctx context.Context) error
	// AttachIO attach the I/O streams from the running to the Wrapper streams.
	AttachIO(ctx context.Context) (IOStreamer, error)
	// Wait blocks until the Exec finishes, errors, or context is canceled.
	Wait(ctx context.Context) error
}

type ExecConfig

type ExecConfig struct {
	IOStream IOStream // IOStream the input/output streams.
	Command  Command  // Command the command to execute.
	TTY      bool     // TTY enable tty on the exec
}

type HasIOStream

type HasIOStream interface {
	// IOStream retrieves the IOStream set
	IOStream() IOStream
	// SetIOStream sets new IOStream
	SetIOStream(IOStream)
}

type IOStream

type IOStream struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

IOStream allows to set the input/output streams for the container or exec

type IOStreamer

type IOStreamer interface {
	Start()
	Wait(ctx context.Context) error
}

func NewIOStreamer

func NewIOStreamer(r types.HijackedResponse, ioStream IOStream) IOStreamer

type Image

type Image interface {
	HasIOStream
	Pull(ctx context.Context) error
	Inspect(ctx context.Context) (types.ImageInspect, error)
}

func NewImage

func NewImage(img string, ioStream IOStream) Image

Directories

Path Synopsis
Package mock_docker is a generated GoMock package.
Package mock_docker is a generated GoMock package.
client
Package mock_client is a generated GoMock package.
Package mock_client is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL