Documentation
¶
Overview ¶
Package compat gates newer Docker daemon features behind the API version a daemon actually speaks, so container creation works against older daemons.
Index ¶
- Constants
- func ConnectContainerExtraNetworksForDockerAPI(ctx context.Context, dockerClient client.APIClient, containerID string, ...) error
- func ContainerCreateWithCompatibility(ctx context.Context, dockerClient client.APIClient, req CreateRequest) (client.ContainerCreateResult, error)
- func ContainerInspectWithCompatibility(ctx context.Context, apiClient client.APIClient, containerID string, ...) (client.ContainerInspectResult, error)
- func DetectDockerAPIVersion(ctx context.Context, dockerClient client.APIClient) string
- func IsDockerAPIVersionAtLeast(current, minimum string) bool
- func NetworkInspectWithCompatibility(ctx context.Context, apiClient client.APIClient, networkID string, ...) (client.NetworkInspectResult, error)
- func NetworkListWithCompatibility(ctx context.Context, apiClient client.APIClient, ...) (client.NetworkListResult, error)
- func PrepareContainerCreateOptionsForDockerAPI(options client.ContainerCreateOptions, apiVersion string) (client.ContainerCreateOptions, map[string]*network.EndpointSettings)
- func SanitizeContainerCreateEndpointSettingsForDockerAPI(endpoints map[string]*network.EndpointSettings, apiVersion string) map[string]*network.EndpointSettings
- func WrapDockerAPIClientForInspectCompatibility(apiClient client.APIClient) client.APIClient
- type CreateRequest
- type EngineCompatibilityInfo
Constants ¶
const ( // NetworkScopedMacAddressMinAPIVersion is the first API version that accepts a // per-network MAC address in endpoint settings. NetworkScopedMacAddressMinAPIVersion = "1.44" // MultiEndpointContainerCreateMinAPIVersion is the first API version that // reliably accepts multiple NetworkingConfig.EndpointsConfig entries on // ContainerCreate. Older daemons need the container created on one network and // the rest attached with NetworkConnect before start, which the host Compose // CLI does on its own but in-process API callers must do themselves. MultiEndpointContainerCreateMinAPIVersion = "1.44" )
Variables ¶
This section is empty.
Functions ¶
func ConnectContainerExtraNetworksForDockerAPI ¶
func ConnectContainerExtraNetworksForDockerAPI(ctx context.Context, dockerClient client.APIClient, containerID string, endpoints map[string]*network.EndpointSettings) error
ConnectContainerExtraNetworksForDockerAPI attaches, in name order, the endpoints withheld from ContainerCreate. Call it after create and before start.
func ContainerCreateWithCompatibility ¶
func ContainerCreateWithCompatibility(ctx context.Context, dockerClient client.APIClient, req CreateRequest) (client.ContainerCreateResult, error)
ContainerCreateWithCompatibility creates the container with the compatibility shims for req's API version applied, attaching withheld networks before returning and removing the container when an attachment fails. The removal ignores ctx cancellation, since an attachment that failed because ctx expired must still not leave the half-connected container behind.
func ContainerInspectWithCompatibility ¶
func ContainerInspectWithCompatibility(ctx context.Context, apiClient client.APIClient, containerID string, options client.ContainerInspectOptions) (client.ContainerInspectResult, error)
ContainerInspectWithCompatibility retries a failed typed decode against the raw daemon JSON, stripping CIDR suffixes that newer Moby address types reject.
func DetectDockerAPIVersion ¶
DetectDockerAPIVersion returns the client's negotiated API version, falling back to the daemon-reported version when the client has none yet.
func IsDockerAPIVersionAtLeast ¶
IsDockerAPIVersionAtLeast compares dotted API versions such as "1.43" and "1.44.1" numerically. It reports false when either side does not parse.
func NetworkInspectWithCompatibility ¶
func NetworkInspectWithCompatibility(ctx context.Context, apiClient client.APIClient, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error)
NetworkInspectWithCompatibility retries a failed typed decode against the raw daemon JSON, stripping CIDR suffixes that newer Moby address types reject.
func NetworkListWithCompatibility ¶
func NetworkListWithCompatibility(ctx context.Context, apiClient client.APIClient, options client.NetworkListOptions) (client.NetworkListResult, error)
NetworkListWithCompatibility retries a failed typed decode against the raw daemon JSON, stripping CIDR suffixes that newer Moby address types reject.
func PrepareContainerCreateOptionsForDockerAPI ¶
func PrepareContainerCreateOptionsForDockerAPI(options client.ContainerCreateOptions, apiVersion string) (client.ContainerCreateOptions, map[string]*network.EndpointSettings)
PrepareContainerCreateOptionsForDockerAPI keeps only the primary network in the create request on daemons older than MultiEndpointContainerCreateMinAPIVersion and returns the withheld endpoints for ConnectContainerExtraNetworksForDockerAPI. The primary network is the named NetworkMode when it has an endpoint, or the first endpoint by name when NetworkMode is unset; host, none, container, and unknown named modes leave the request untouched.
func SanitizeContainerCreateEndpointSettingsForDockerAPI ¶
func SanitizeContainerCreateEndpointSettingsForDockerAPI(endpoints map[string]*network.EndpointSettings, apiVersion string) map[string]*network.EndpointSettings
SanitizeContainerCreateEndpointSettingsForDockerAPI deep-copies endpoint settings and drops per-network MAC addresses on daemons older than NetworkScopedMacAddressMinAPIVersion.
Types ¶
type CreateRequest ¶
type CreateRequest struct {
// Options are the create options before any compatibility shim is applied.
Options client.ContainerCreateOptions
// APIVersion is the daemon API version the shims target. Empty detects it
// with DetectDockerAPIVersion.
APIVersion string
}
CreateRequest is the container ContainerCreateWithCompatibility creates.
type EngineCompatibilityInfo ¶
type EngineCompatibilityInfo struct {
// Name is the normalized engine identifier, "docker" or "podman".
Name string
// CgroupVersion is the daemon-reported cgroup version, such as "1" or "2".
CgroupVersion string
}
EngineCompatibilityInfo describes the container engine details that decide whether recreate-time HostConfig sanitization is required.
func DetectEngineCompatibility ¶
func DetectEngineCompatibility(version client.ServerVersionResult, info systemtypes.Info) EngineCompatibilityInfo
DetectEngineCompatibility derives the engine name from the daemon's version and info responses, checking the platform, components, and OS markers in order.
func PrepareRecreateHostConfigForEngine ¶
func PrepareRecreateHostConfigForEngine( ctx context.Context, dockerClient client.APIClient, containerID string, hostConfig *containertypes.HostConfig, ) (*containertypes.HostConfig, bool, EngineCompatibilityInfo, error)
PrepareRecreateHostConfigForEngine shallow-copies hostConfig and removes the options the connected engine rejects, returning the copy, whether anything was removed, and the engine details behind that decision.
func (EngineCompatibilityInfo) SanitizeRecreateHostConfig ¶
func (e EngineCompatibilityInfo) SanitizeRecreateHostConfig(hostConfig *containertypes.HostConfig) bool
SanitizeRecreateHostConfig removes recreate options the engine rejects: Podman on cgroup v2 refuses MemorySwappiness. It reports whether anything was removed.