Documentation
¶
Index ¶
- func CreateContainer(ctx context.Context, log *log.Logger, c *client.Client, ...) (string, error)
- func ExecuteCommand(ctx context.Context, c *client.Client, id string, cmd []string) (client.ExecInspectResult, error)
- func GetImageMajorVersion(image string) int
- type ContainerVolume
- type ManagedContainerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateContainer ¶
func CreateContainer(ctx context.Context, log *log.Logger, c *client.Client, a mconfig.ContainerAllocation, opts ManagedContainerOptions) (string, error)
CreateContainer finds and removes any existing container with the given name, then creates a fresh one from the provided options.
Existing Docker volumes are always preserved so that data survives a container re-creation. Returns the ID of the newly created container.
func ExecuteCommand ¶
func ExecuteCommand(ctx context.Context, c *client.Client, id string, cmd []string) (client.ExecInspectResult, error)
Simply execute a command inside of a container.
func GetImageMajorVersion ¶
GetImageMajorVersion extracts the major version number from a Docker image tag. It searches for the first sequence of digits in the tag portion of the image name (after the colon) and returns it as an integer. For example:
- "postgres:17" -> 17
- "node:v20.1.0" -> 20
- "nginx:1.25-alpine" -> 1
Returns -1 if no version number can be found.
Types ¶
type ContainerVolume ¶
type ContainerVolume struct {
// Suffix appended to the container name to form the Docker volume name,
// e.g. "data" -> "<containerName>-data".
NameSuffix string
// Absolute path inside the container where the volume is mounted.
Target string
}
ContainerVolume describes a single named volume that should be mounted into the container. The volume name is derived from the container name so it survives container re-creation.
type ManagedContainerOptions ¶
type ManagedContainerOptions struct {
// Docker image to use, e.g. "postgres:17".
Image string
// Environment variables passed into the container.
Env []string
// Ports to expose. Each entry maps one container port (inside of the container) to one host port (chosen by Magic).
Ports []string
// Named volumes to attach. Existing mounts are reused across re-creations.
Volumes []ContainerVolume
}
ManagedContainerOptions holds everything needed to create (or re-create) a managed Docker container in a reproducible way.