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 FindContainer(ctx context.Context, c *client.Client, name string) (*container.InspectResponse, 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 looks for an existing container with the given name and reuses it when its configuration still matches the requested options.
When the configuration differs (image, env, command, ports, volumes), it removes the old container and 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 currently running/reusable or freshly 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 FindContainer ¶
func FindContainer(ctx context.Context, c *client.Client, name string) (*container.InspectResponse, error)
FindContainer looks for a container with the given name and returns its inspect data. Returns nil when no container matches.
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
// Commands to run in the container (overrides the image's default CMD).
Cmd []string
}
ManagedContainerOptions holds everything needed to create (or re-create) a managed Docker container in a reproducible way.