Documentation
¶
Index ¶
- func BuildDockerfile(ctx context.Context, dockerfilePath string) (string, string, error)
- func CleanupAndKillContainer(ctx context.Context, client *docker.Client, name string) error
- func CreateNetwork(ctx context.Context, name string, labels map[string]string) (bool, error)
- func DeleteImage(ctx context.Context, client *docker.Client, image string, tag string) error
- func DockerAvailable() bool
- func ImageExists(ctx context.Context, client *docker.Client, image string, tag string) (bool, error)
- func LogsFromContainers(ctx context.Context, containers ...*Container) (logs.LogStreams, error)
- func MergeContainerLogs(ctx context.Context, containers ...*Container) (io.ReadCloser, error)
- func NewClient(ctx context.Context) (*docker.Client, error)
- func RemoveNetwork(ctx context.Context, name string) error
- type Container
- func (c *Container) Address(port string) string
- func (c *Container) Cleanup(ctx context.Context) error
- func (c *Container) Client() *docker.Client
- func (c *Container) DeleteImage(ctx context.Context) error
- func (c *Container) GetContainerID() string
- func (c *Container) GetPorts() map[string]string
- func (c *Container) HostPort(port string) (string, bool)
- func (c *Container) ImageExists(ctx context.Context) (bool, error)
- func (c *Container) IsRunning(ctx context.Context) (bool, error)
- func (c *Container) Kill(ctx context.Context) error
- func (c *Container) Labels() map[string]string
- func (c *Container) Logs(ctx context.Context) (io.ReadCloser, error)
- func (c *Container) Name() string
- func (c *Container) SetLabels(labels map[string]string)
- func (c *Container) SetNamePrefix(prefix string)
- func (c *Container) SetNetwork(name string)
- func (c *Container) Start(ctx context.Context) (err error)
- func (c *Container) Stop(ctx context.Context, wait int) error
- func (c *Container) URL(scheme string, port string) string
- func (c *Container) WaitForLogText(ctx context.Context, text string, timeout time.Duration) error
- type ContainerOption
- func WithBind(hostPath string, containerPath string) ContainerOption
- func WithCommand(command ...string) ContainerOption
- func WithEnv(env map[string]string) ContainerOption
- func WithHostIP(hostIP string) ContainerOption
- func WithLabels(labels map[string]string) ContainerOption
- func WithNetwork(name string) ContainerOption
- func WithPort(containerPort string, hostPort string) ContainerOption
- func WithPorts(ports map[string]string) ContainerOption
- func WithTag(tag string) ContainerOption
- type Harness
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDockerfile ¶
BuildDockerfile builds the Dockerfile at dockerfilePath. The build context is the Dockerfile's directory. It returns the image id Docker reported, the combined Docker build logs, and any error.
func CleanupAndKillContainer ¶
CleanupAndKillContainer kills and removes a container by name, then removes anonymous volumes that were attached to that container.
func CreateNetwork ¶
CreateNetwork creates a Docker network if it does not already exist.
func DeleteImage ¶
DeleteImage removes a specific image/tag from the local machine.
func DockerAvailable ¶
func DockerAvailable() bool
DockerAvailable returns true when a Docker daemon is reachable from the current environment.
func ImageExists ¶
func ImageExists(ctx context.Context, client *docker.Client, image string, tag string) (bool, error)
ImageExists will return true if the image/tag exists, false otherwise. A blank tag is assumed to be "latest".
func LogsFromContainers ¶
LogsFromContainers returns one named log stream for each container. Named containers use their Docker name. Unnamed containers receive a stable container-N key based on argument order.
func MergeContainerLogs ¶
MergeContainerLogs opens logs for N containers and merges them into one reader.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a small wrapper around the Docker API. It owns the Docker container id, assigned host ports, environment variables, bind mounts, and anonymous volumes that should be removed during cleanup.
func NewContainer ¶
func NewContainer(name string, image string, options ...ContainerOption) (*Container, error)
NewContainer builds a container harness for an image. A blank tag is assumed to be "latest". If a port mapping has an empty host port, scaffold will assign a free host port when the container starts.
func (*Container) Address ¶
Address returns localhost:port for a container port. If the port is not published, it returns an empty string.
func (*Container) Cleanup ¶
Cleanup kills the container if it is still running, removes it, and then removes anonymous volumes that were attached to it.
func (*Container) DeleteImage ¶
DeleteImage removes the container image/tag from the local machine.
func (*Container) GetContainerID ¶
GetContainerID returns the Docker container id assigned during Start.
func (*Container) GetPorts ¶
GetPorts returns the container port to host port mapping. Host ports are available after Start has assigned them.
func (*Container) ImageExists ¶
ImageExists will return true if the image/tag exists, false otherwise. A blank tag is assumed to be "latest".
func (*Container) Kill ¶
Kill immediately terminates the container without waiting for graceful shutdown inside the container.
func (*Container) SetNamePrefix ¶
SetNamePrefix prefixes the Docker container name if one was configured. Stacks call this before creation for services that opt into generated resource names.
func (*Container) SetNetwork ¶
SetNetwork updates the Docker network name for the container. Stacks use this to attach services to a shared network before creation.
func (*Container) Start ¶
Start pulls the image if needed and starts the container. If port mappings are configured with an empty host port, a free port is assigned before the container is created.
func (*Container) Stop ¶
Stop sends SIGTERM and waits up to the given number of seconds. If the container does not stop in time, or wait is <= 0, it is killed with SIGKILL.
type ContainerOption ¶
type ContainerOption func(*Container)
ContainerOption allows callers to tune a container without making the common constructor path noisy.
func WithBind ¶
func WithBind(hostPath string, containerPath string) ContainerOption
WithBind mounts a host path into the container. This is intentionally simple and maps directly to Docker's bind syntax.
func WithCommand ¶
func WithCommand(command ...string) ContainerOption
WithCommand sets the container command. This is useful for images like MinIO that require a command to start the desired service.
func WithEnv ¶
func WithEnv(env map[string]string) ContainerOption
WithEnv adds container process environment variables. These values are sent to Docker as KEY=VALUE entries when the container starts.
func WithHostIP ¶
func WithHostIP(hostIP string) ContainerOption
WithHostIP sets the host IP used for published container ports. The default is 127.0.0.1 for local-only services.
func WithLabels ¶
func WithLabels(labels map[string]string) ContainerOption
WithLabels adds Docker labels to the container. These labels are merged with any labels inherited from a parent stack.
func WithNetwork ¶
func WithNetwork(name string) ContainerOption
WithNetwork attaches the container to an existing Docker network when it is created.
func WithPort ¶
func WithPort(containerPort string, hostPort string) ContainerOption
WithPort adds one container port to host port mapping. An empty host port asks scaffold to assign a free host port when the container starts.
func WithPorts ¶
func WithPorts(ports map[string]string) ContainerOption
WithPorts adds container port to host port mappings. An empty host port asks scaffold to assign a free host port when the container starts.
func WithTag ¶
func WithTag(tag string) ContainerOption
WithTag sets the image tag used when the container starts. A blank tag keeps the default tag, "latest".