Documentation ¶
Overview ¶
Package container implements a fluent interface for creating and starting docker containers.
Package container implements a fluent interface for creating and starting docker containers.
Index ¶
- type ContainerBuilder
- type ContainerWaitResult
- type DockerContainerBuilder
- func (dc *DockerContainerBuilder) Create() *DockerContainerBuilder
- func (dc *DockerContainerBuilder) GetContainerID() *string
- func (dc *DockerContainerBuilder) GetNetworkIDs() []string
- func (dc *DockerContainerBuilder) Start() (bool, error)
- func (dc *DockerContainerBuilder) StartWaitUntilExit() (*ContainerWaitResult, error)
- func (dc *DockerContainerBuilder) WithAutoRemove(remove bool) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithClient(cli *client.Client) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithCmd(cmd []string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithEntrypoint(entrypoint []string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithEnv(envList []string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithForcePullImage() *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithImage(imageWithTag string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithLabels(labels map[string]string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithLogConfig(logConfig *container.LogConfig) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithLogWriter(logger io.StringWriter) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithMountPoints(mountList []mount.Mount) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithName(name string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithNetworkAliases(aliases ...string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithNetworkMode(networkMode string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithNetworks(networks []string) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithPortBindings(portList []PortBinding) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithPortRanges(portRanges []PortRangeBinding) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithPostCreateHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithPostStartHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithPreCreateHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithPreStartHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithRegistryAuth(auth *RegistryAuth) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithRestartPolicy(policy RestartPolicyName) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithTTY(tty bool) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithUser(user *int64) *DockerContainerBuilder
- func (dc *DockerContainerBuilder) WithoutConflict() *DockerContainerBuilder
- type DockerExecBuilder
- func (de *DockerExecBuilder) Create() (Exec, error)
- func (de *DockerExecBuilder) WithAttachStderr() *DockerExecBuilder
- func (de *DockerExecBuilder) WithAttachStdin() *DockerExecBuilder
- func (de *DockerExecBuilder) WithAttachStdout() *DockerExecBuilder
- func (de *DockerExecBuilder) WithClient(cli *client.Client) *DockerExecBuilder
- func (de *DockerExecBuilder) WithCmd(cmd []string) *DockerExecBuilder
- func (de *DockerExecBuilder) WithDetach() *DockerExecBuilder
- func (de *DockerExecBuilder) WithLogWriter(logger io.StringWriter) *DockerExecBuilder
- func (de *DockerExecBuilder) WithPrivileged() *DockerExecBuilder
- func (de *DockerExecBuilder) WithTTY() *DockerExecBuilder
- func (de *DockerExecBuilder) WithUser(user *int64) *DockerExecBuilder
- func (de *DockerExecBuilder) WithWorkingDir(workingDir string) *DockerExecBuilder
- type ErrRestartPolicyUnmarshalInvalid
- type Exec
- type ExecBuilder
- type ImagePullResponse
- type LifecycleFunc
- type PortBinding
- type PortRange
- type PortRangeBinding
- type RegistryAuth
- type RestartPolicyName
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContainerBuilder ¶
type ContainerBuilder interface { WithClient(client *client.Client) ContainerBuilder WithImage(imageName string) ContainerBuilder WithEnv(env []string) ContainerBuilder WithPortBindings(portList []PortBinding) ContainerBuilder WithPortRange(portRanges []PortRange) ContainerBuilder WithMountPoints(mounts []mount.Mount) ContainerBuilder WithName(name string) ContainerBuilder WithNetworkAliases(aliases ...string) ContainerBuilder WithNetworkMode(networkMode string) ContainerBuilder WithNetworks(networks []string) ContainerBuilder WithLabels(labels map[string]string) ContainerBuilder WithLogConfig(config container.LogConfig) WithRegistryAuth(auth RegistryAuth) ContainerBuilder WithAutoRemove(remove bool) ContainerBuilder WithRestartPolicy(policy RestartPolicyName) ContainerBuilder WithEntrypoint(cmd []string) ContainerBuilder WithCmd(cmd []string) ContainerBuilder WithUser(uid string) ContainerBuilder WithLogWriter(logger io.StringWriter) ContainerBuilder WithoutConflict() ContainerBuilder WithForcePullImage() ContainerBuilder WithPreCreateHooks(hooks ...LifecycleFunc) ContainerBuilder WithPostCreateHooks(hooks ...LifecycleFunc) ContainerBuilder WithPreStartHooks(hooks ...LifecycleFunc) ContainerBuilder WithPostStartHooks(hooks ...LifecycleFunc) ContainerBuilder Create() ContainerBuilder GetContainerID() *string GetNetworkID() *string Start() (bool, error) StartWaitUntilExit() (ContainerWaitResult, error) }
A ContainerBuilder handles the process of creating and starting containers, it can be configured using 'With...' methods. A ContainerBuilder can be created using the NewDockerBuilder method.
type ContainerWaitResult ¶
type ContainerWaitResult struct {
StatusCode int64
}
ContainerWaitResult with the status code from the container
type DockerContainerBuilder ¶
type DockerContainerBuilder struct {
// contains filtered or unexported fields
}
func NewDockerBuilder ¶
func NewDockerBuilder(ctx context.Context) *DockerContainerBuilder
A shorthand function for creating a new DockerContainerBuilder and calling WithClient. Creates a default Docker client which can be overwritten using 'WithClient'. Creates a default logger which logs using the 'fmt' package.
func (*DockerContainerBuilder) Create ¶
func (dc *DockerContainerBuilder) Create() *DockerContainerBuilder
Creates the container using the configuration given by 'With...' functions.
func (*DockerContainerBuilder) GetContainerID ¶
func (dc *DockerContainerBuilder) GetContainerID() *string
func (*DockerContainerBuilder) GetNetworkIDs ¶
func (dc *DockerContainerBuilder) GetNetworkIDs() []string
func (*DockerContainerBuilder) Start ¶
func (dc *DockerContainerBuilder) Start() (bool, error)
Starts the container using the configuration given by 'With...' functions. Returns true if successful, false and an error if not.
func (*DockerContainerBuilder) StartWaitUntilExit ¶
func (dc *DockerContainerBuilder) StartWaitUntilExit() (*ContainerWaitResult, error)
Starts the container and waits until the first exit to happen then returns
func (*DockerContainerBuilder) WithAutoRemove ¶
func (dc *DockerContainerBuilder) WithAutoRemove(remove bool) *DockerContainerBuilder
Sets if the container should be removed after it exists.
func (*DockerContainerBuilder) WithClient ¶
func (dc *DockerContainerBuilder) WithClient(cli *client.Client) *DockerContainerBuilder
Sets the Docker client of the ContainerBuilder. By default NewDockerBuilder creates a client.
func (*DockerContainerBuilder) WithCmd ¶
func (dc *DockerContainerBuilder) WithCmd(cmd []string) *DockerContainerBuilder
Sets the CMD of a container.
func (*DockerContainerBuilder) WithEntrypoint ¶
func (dc *DockerContainerBuilder) WithEntrypoint(entrypoint []string) *DockerContainerBuilder
Sets the entrypoint of a container.
func (*DockerContainerBuilder) WithEnv ¶
func (dc *DockerContainerBuilder) WithEnv(envList []string) *DockerContainerBuilder
Sets the environment variables of a container. Values are in a "KEY=VALUE" format.
func (*DockerContainerBuilder) WithForcePullImage ¶
func (dc *DockerContainerBuilder) WithForcePullImage() *DockerContainerBuilder
Sets the builder to force pull the image before creating the container.
func (*DockerContainerBuilder) WithImage ¶
func (dc *DockerContainerBuilder) WithImage(imageWithTag string) *DockerContainerBuilder
Sets the image of a container in a "image:tag" format where image can be a fully qualified name.
func (*DockerContainerBuilder) WithLabels ¶
func (dc *DockerContainerBuilder) WithLabels(labels map[string]string) *DockerContainerBuilder
Sets the labels of a container.
func (*DockerContainerBuilder) WithLogConfig ¶
func (dc *DockerContainerBuilder) WithLogConfig(logConfig *container.LogConfig) *DockerContainerBuilder
Sets the log config of the container.
func (*DockerContainerBuilder) WithLogWriter ¶
func (dc *DockerContainerBuilder) WithLogWriter(logger io.StringWriter) *DockerContainerBuilder
Sets the logger which logs messages releated to the builder (and not the container).
func (*DockerContainerBuilder) WithMountPoints ¶
func (dc *DockerContainerBuilder) WithMountPoints(mountList []mount.Mount) *DockerContainerBuilder
Sets mount points of a container.
func (*DockerContainerBuilder) WithName ¶
func (dc *DockerContainerBuilder) WithName(name string) *DockerContainerBuilder
Sets the name of the target container.
func (*DockerContainerBuilder) WithNetworkAliases ¶
func (dc *DockerContainerBuilder) WithNetworkAliases(aliases ...string) *DockerContainerBuilder
Sets the network aliases used when connecting the container to the network. Applied only if the NetworkMode is not none/host. It is a must for Podman, without this the DNS resolution won't work.
func (*DockerContainerBuilder) WithNetworkMode ¶
func (dc *DockerContainerBuilder) WithNetworkMode(networkMode string) *DockerContainerBuilder
Sets the network mode of a container.
func (*DockerContainerBuilder) WithNetworks ¶
func (dc *DockerContainerBuilder) WithNetworks(networks []string) *DockerContainerBuilder
Sets the extra networks.
func (*DockerContainerBuilder) WithPortBindings ¶
func (dc *DockerContainerBuilder) WithPortBindings(portList []PortBinding) *DockerContainerBuilder
Sets the port bindings of a container. Expose internal container ports to the host.
func (*DockerContainerBuilder) WithPortRanges ¶
func (dc *DockerContainerBuilder) WithPortRanges(portRanges []PortRangeBinding) *DockerContainerBuilder
Sets port ranges of a container.
func (*DockerContainerBuilder) WithPostCreateHooks ¶
func (dc *DockerContainerBuilder) WithPostCreateHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
Sets an array of hooks which runs after the container is created.
func (*DockerContainerBuilder) WithPostStartHooks ¶
func (dc *DockerContainerBuilder) WithPostStartHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
Sets an array of hooks which runs after the container is started.
func (*DockerContainerBuilder) WithPreCreateHooks ¶
func (dc *DockerContainerBuilder) WithPreCreateHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
Sets an array of hooks which runs before the container is created. ContainerID is nil in these hooks.
func (*DockerContainerBuilder) WithPreStartHooks ¶
func (dc *DockerContainerBuilder) WithPreStartHooks(hooks ...LifecycleFunc) *DockerContainerBuilder
Sets an array of hooks which runs before the container is started.
func (*DockerContainerBuilder) WithRegistryAuth ¶
func (dc *DockerContainerBuilder) WithRegistryAuth(auth *RegistryAuth) *DockerContainerBuilder
Sets the registry and authentication for the given image.
func (*DockerContainerBuilder) WithRestartPolicy ¶
func (dc *DockerContainerBuilder) WithRestartPolicy(policy RestartPolicyName) *DockerContainerBuilder
Sets the restart policy of the container.
func (*DockerContainerBuilder) WithTTY ¶
func (dc *DockerContainerBuilder) WithTTY(tty bool) *DockerContainerBuilder
Sets if standard streams should be attached to a tty.
func (*DockerContainerBuilder) WithUser ¶
func (dc *DockerContainerBuilder) WithUser(user *int64) *DockerContainerBuilder
Sets the UID.
func (*DockerContainerBuilder) WithoutConflict ¶
func (dc *DockerContainerBuilder) WithoutConflict() *DockerContainerBuilder
Deletes the container with the given name if already exists.
type DockerExecBuilder ¶
type DockerExecBuilder struct {
// contains filtered or unexported fields
}
func NewExecBuilder ¶
func NewExecBuilder(ctx context.Context, containerID *string) *DockerExecBuilder
A shorthand function for creating a new DockerExecBuilder and calling WithClient. Creates a default Docker client which can be overwritten using 'WithClient'. Creates a default logger which logs using the 'fmt' package.
func (*DockerExecBuilder) Create ¶
func (de *DockerExecBuilder) Create() (Exec, error)
Creates the exec command using the configuration given by 'With...' functions.
func (*DockerExecBuilder) WithAttachStderr ¶
func (de *DockerExecBuilder) WithAttachStderr() *DockerExecBuilder
Sets the builder to attach stderr to the exec command
func (*DockerExecBuilder) WithAttachStdin ¶
func (de *DockerExecBuilder) WithAttachStdin() *DockerExecBuilder
Sets the builder to attach stdin to the exec command
func (*DockerExecBuilder) WithAttachStdout ¶
func (de *DockerExecBuilder) WithAttachStdout() *DockerExecBuilder
Sets the builder to attach stdout to the exec command
func (*DockerExecBuilder) WithClient ¶
func (de *DockerExecBuilder) WithClient(cli *client.Client) *DockerExecBuilder
Sets the Docker client of the ExecBuilder. By default NewExecBuilder creates a client.
func (*DockerExecBuilder) WithCmd ¶
func (de *DockerExecBuilder) WithCmd(cmd []string) *DockerExecBuilder
Sets the commands to run as part of exec
func (*DockerExecBuilder) WithDetach ¶
func (de *DockerExecBuilder) WithDetach() *DockerExecBuilder
Sets the builder to detach from the exec command
func (*DockerExecBuilder) WithLogWriter ¶
func (de *DockerExecBuilder) WithLogWriter(logger io.StringWriter) *DockerExecBuilder
Sets the logger which logs messages releated to the builder (and not the container).
func (*DockerExecBuilder) WithPrivileged ¶
func (de *DockerExecBuilder) WithPrivileged() *DockerExecBuilder
Sets the builder to run the exec process with extended privileges.
func (*DockerExecBuilder) WithTTY ¶
func (de *DockerExecBuilder) WithTTY() *DockerExecBuilder
Sets if standard streams should be attached to a tty.
func (*DockerExecBuilder) WithUser ¶
func (de *DockerExecBuilder) WithUser(user *int64) *DockerExecBuilder
Sets the UID.
func (*DockerExecBuilder) WithWorkingDir ¶
func (de *DockerExecBuilder) WithWorkingDir(workingDir string) *DockerExecBuilder
Sets the working directory for the exec process inside the container.
type ErrRestartPolicyUnmarshalInvalid ¶
type ErrRestartPolicyUnmarshalInvalid struct{}
RestartPolicyUnmarshalInvalidError represents custom error regarding restart policy
func (*ErrRestartPolicyUnmarshalInvalid) Error ¶
func (e *ErrRestartPolicyUnmarshalInvalid) Error() string
type ExecBuilder ¶
type ExecBuilder interface { WithAttachStderr() *DockerExecBuilder WithAttachStdin() *DockerExecBuilder WithAttachStdout() *DockerExecBuilder WithClient(client *client.Client) *DockerExecBuilder WithCmd(cmd []string) *DockerExecBuilder WithDetach() *DockerExecBuilder WithLogWriter(logger io.StringWriter) *DockerExecBuilder WithPrivileged() *DockerExecBuilder WithTTY() *DockerExecBuilder WithUser(user *int64) *DockerExecBuilder WithWorkingDir(workingDir string) *DockerExecBuilder Create() (Exec, error) }
An ExecBuilder handles the process of creating and starting exec, it can be configured using 'With...' methods. An ExecBuilder can be created using the DockerExecBuilder method.
type ImagePullResponse ¶
type ImagePullResponse struct { ID string `json:"id"` Status string `json:"status"` ProgressDetail struct { Current int64 `json:"current"` Total int64 `json:"total"` } `json:"progressDetail"` Progress string `json:"progress"` }
ImagePullResponse is not explicit
type LifecycleFunc ¶
type LifecycleFunc func(ctx context.Context, client *client.Client, containerName string, containerId *string, mountList []mount.Mount, logger *io.StringWriter) error
Hook function which can be used to add custom logic before and after events of the lifecycle of a container. 'containerId' can be nil depending on the hook.
type PortBinding ¶
type PortBinding struct { ExposedPort uint16 `json:"exposedPort" binding:"required,gte=0,lte=65535"` PortBinding uint16 `json:"portBinding" binding:"required,gte=0,lte=65535"` }
The PortBinding struct defines port bindings of a container. ExposedPort is the port in the container, while PortBinding is the port on the host.
type PortRange ¶
type PortRange struct { From uint16 `json:"from" binding:"required,gte=0,lte=65535"` To uint16 `json:"to" binding:"required,gtefield=From,lte=65535"` }
PortRange defines a range of ports from 0 to 65535.
type PortRangeBinding ¶
type PortRangeBinding struct { Internal PortRange `json:"internal" binding:"required"` External PortRange `json:"external" binding:"required"` }
PortRangeBinding defines port range bindings of a container. Internal is the port in the container, while External is the port on the host.
type RegistryAuth ¶
type RegistryAuth struct { Name string `json:"name" binding:"required"` URL string `json:"url" binding:"required"` User string `json:"user" binding:"required"` Password string `json:"password" binding:"required"` }
RegistryAuth defines an image registry and the authentication information associated with it.
type RestartPolicyName ¶
type RestartPolicyName string
RestartPolicyName defines the restart policy used by a container.
const ( EmptyRestartPolicy RestartPolicyName = "" AlwaysRestartPolicy RestartPolicyName = "always" RestartUnlessStoppedRestartPolicy RestartPolicyName = "unless-stopped" NoRestartPolicy RestartPolicyName = "no" OnFailureRestartPolicy RestartPolicyName = "on-failure" )
func (RestartPolicyName) MarshalJSON ¶
func (policy RestartPolicyName) MarshalJSON() ([]byte, error)
custom enum marshal JSON interface implementation
func (*RestartPolicyName) UnmarshalJSON ¶
func (policy *RestartPolicyName) UnmarshalJSON(b []byte) error
custom enum unmarshal JSON interface implementation