compat

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: BSD-3-Clause Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Docker Compat

This package is a compatibility package to gate newer daemon features on older docker daemon api versions

License

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

View Source
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

func DetectDockerAPIVersion(ctx context.Context, dockerClient client.APIClient) string

DetectDockerAPIVersion returns the client's negotiated API version, falling back to the daemon-reported version when the client has none yet.

func IsDockerAPIVersionAtLeast

func IsDockerAPIVersionAtLeast(current, minimum string) bool

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.

func WrapDockerAPIClientForInspectCompatibility

func WrapDockerAPIClientForInspectCompatibility(apiClient client.APIClient) client.APIClient

WrapDockerAPIClientForInspectCompatibility wraps a client so create, inspect, and list calls apply the daemon compatibility shims transparently.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL