1.0.28
This commit is contained in:
46 files changed
+7202
-233
No files matched your search
@@ -1248,6 +1248,12 @@ export interface CreateContainerOptions {
|
||||
networkIpv6Address?: string;
|
||||
/** Gateway priority for the primary network (Docker Engine 28+) */
|
||||
networkGwPriority?: number;
|
||||
/** Per-network endpoint configuration (IPv4, IPv6, aliases) */
|
||||
networkConfigs?: Record<string, {
|
||||
ipv4Address?: string;
|
||||
ipv6Address?: string;
|
||||
aliases?: string[];
|
||||
}>;
|
||||
user?: string | null;
|
||||
privileged?: boolean;
|
||||
healthcheck?: HealthcheckConfig | null;
|
||||
@@ -1431,10 +1437,25 @@ export async function createContainer(options: CreateContainerOptions, envId?: n
|
||||
|
||||
for (const network of options.networks) {
|
||||
const isFirstNetwork = network === options.networks[0];
|
||||
const netCfg = options.networkConfigs?.[network];
|
||||
const endpointConfig: any = {};
|
||||
|
||||
// Apply aliases, static IP, and gateway priority only to the first (primary) network
|
||||
if (isFirstNetwork) {
|
||||
// Per-network config from networkConfigs (takes precedence)
|
||||
if (netCfg) {
|
||||
if (netCfg.aliases && netCfg.aliases.length > 0) {
|
||||
endpointConfig.Aliases = netCfg.aliases;
|
||||
}
|
||||
if (netCfg.ipv4Address || netCfg.ipv6Address) {
|
||||
endpointConfig.IPAMConfig = {};
|
||||
if (netCfg.ipv4Address) {
|
||||
endpointConfig.IPAMConfig.IPv4Address = netCfg.ipv4Address;
|
||||
}
|
||||
if (netCfg.ipv6Address) {
|
||||
endpointConfig.IPAMConfig.IPv6Address = netCfg.ipv6Address;
|
||||
}
|
||||
}
|
||||
} else if (isFirstNetwork) {
|
||||
// Backward compat: apply flat fields to first network if no networkConfigs
|
||||
if (options.networkAliases && options.networkAliases.length > 0) {
|
||||
endpointConfig.Aliases = options.networkAliases;
|
||||
}
|
||||
@@ -1617,9 +1638,22 @@ export async function createContainer(options: CreateContainerOptions, envId?: n
|
||||
containerConfig.StopTimeout = options.stopTimeout;
|
||||
}
|
||||
|
||||
// MAC address
|
||||
// MAC address — set both top-level (API <1.44) and endpoint config (API 1.44+)
|
||||
if (options.macAddress) {
|
||||
containerConfig.MacAddress = options.macAddress;
|
||||
|
||||
// For Docker API 1.44+, MacAddress must be in EndpointConfig
|
||||
const primaryNetwork = options.networks?.[0] || options.networkMode || 'bridge';
|
||||
if (containerConfig.NetworkingConfig?.EndpointsConfig?.[primaryNetwork]) {
|
||||
containerConfig.NetworkingConfig.EndpointsConfig[primaryNetwork].MacAddress = options.macAddress;
|
||||
} else {
|
||||
containerConfig.NetworkingConfig = containerConfig.NetworkingConfig || { EndpointsConfig: {} };
|
||||
containerConfig.NetworkingConfig.EndpointsConfig = containerConfig.NetworkingConfig.EndpointsConfig || {};
|
||||
containerConfig.NetworkingConfig.EndpointsConfig[primaryNetwork] = {
|
||||
...containerConfig.NetworkingConfig.EndpointsConfig[primaryNetwork],
|
||||
MacAddress: options.macAddress
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Extra hosts (/etc/hosts entries)
|
||||
@@ -2325,11 +2359,15 @@ export async function updateContainer(id: string, options: Partial<CreateContain
|
||||
const mergedOptions: CreateContainerOptions = {
|
||||
...existingOptions,
|
||||
...options,
|
||||
// Special handling for labels - merge instead of replace to preserve Docker internal labels
|
||||
labels: {
|
||||
...existingOptions.labels,
|
||||
...options.labels
|
||||
}
|
||||
// Replace labels, but preserve Docker internal labels (com.docker.*)
|
||||
labels: options.labels !== undefined
|
||||
? {
|
||||
...Object.fromEntries(
|
||||
Object.entries(existingOptions.labels || {}).filter(([k]) => k.startsWith('com.docker.'))
|
||||
),
|
||||
...options.labels
|
||||
}
|
||||
: existingOptions.labels
|
||||
};
|
||||
|
||||
// 1. Stop old container
|
||||
|
||||
Reference in new issue
Block a user