Repository: compose-spec/compose-go
Pull request #772 (2025-04-23 08:19:04)

introduce networks.interface_name
see https://github.com/docker/compose/issues/12740


Patch:
diff --git a/schema/compose-spec.json b/schema/compose-spec.json
index d6d4a0c..35c1854 100644
--- a/schema/compose-spec.json
+++ b/schema/compose-spec.json
@@ -323,6 +323,7 @@
                       "type": "object",
                       "properties": {
                         "aliases": {"$ref": "#/definitions/list_of_strings"},
+                        "interface_name": {"type": "string"},
                         "ipv4_address": {"type": "string"},
                         "ipv6_address": {"type": "string"},
                         "link_local_ips": {"$ref": "#/definitions/list_of_strings"},
diff --git a/types/derived.gen.go b/types/derived.gen.go
index 2d60dae..4e3278f 100644
--- a/types/derived.gen.go
+++ b/types/derived.gen.go
@@ -1834,8 +1834,6 @@ func deriveDeepCopy_39(dst, src *DeviceRequest) {
 
 // deriveDeepCopy_40 recursively copies the contents of src into dst.
 func deriveDeepCopy_40(dst, src *ServiceNetworkConfig) {
-	dst.Priority = src.Priority
-	dst.GatewayPriority = src.GatewayPriority
 	if src.Aliases == nil {
 		dst.Aliases = nil
 	} else {
@@ -1854,6 +1852,14 @@ func deriveDeepCopy_40(dst, src *ServiceNetworkConfig) {
 		}
 		copy(dst.Aliases, src.Aliases)
 	}
+	if src.DriverOpts != nil {
+		dst.DriverOpts = make(map[string]string, len(src.DriverOpts))
+		deriveDeepCopy_4(dst.DriverOpts, src.DriverOpts)
+	} else {
+		dst.DriverOpts = nil
+	}
+	dst.GatewayPriority = src.GatewayPriority
+	dst.InterfaceName = src.InterfaceName
 	dst.Ipv4Address = src.Ipv4Address
 	dst.Ipv6Address = src.Ipv6Address
 	if src.LinkLocalIPs == nil {
@@ -1875,12 +1881,7 @@ func deriveDeepCopy_40(dst, src *ServiceNetworkConfig) {
 		copy(dst.LinkLocalIPs, src.LinkLocalIPs)
 	}
 	dst.MacAddress = src.MacAddress
-	if src.DriverOpts != nil {
-		dst.DriverOpts = make(map[string]string, len(src.DriverOpts))
-		deriveDeepCopy_4(dst.DriverOpts, src.DriverOpts)
-	} else {
-		dst.DriverOpts = nil
-	}
+	dst.Priority = src.Priority
 	if src.Extensions != nil {
 		dst.Extensions = make(map[string]any, len(src.Extensions))
 		src.Extensions.DeepCopy(dst.Extensions)
diff --git a/types/types.go b/types/types.go
index acfb355..61d1615 100644
--- a/types/types.go
+++ b/types/types.go
@@ -470,14 +470,15 @@ type PlacementPreferences struct {
 
 // ServiceNetworkConfig is the network configuration for a service
 type ServiceNetworkConfig struct {
-	Priority        int      `yaml:"priority,omitempty" json:"priority,omitempty"`
-	GatewayPriority int      `yaml:"gw_priority,omitempty" json:"gw_priority,omitempty"`
 	Aliases         []string `yaml:"aliases,omitempty" json:"aliases,omitempty"`
+	DriverOpts      Options  `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
+	GatewayPriority int      `yaml:"gw_priority,omitempty" json:"gw_priority,omitempty"`
+	InterfaceName   string   `yaml:"interface_name,omitempty" json:"interface_name,omitempty"`
 	Ipv4Address     string   `yaml:"ipv4_address,omitempty" json:"ipv4_address,omitempty"`
 	Ipv6Address     string   `yaml:"ipv6_address,omitempty" json:"ipv6_address,omitempty"`
 	LinkLocalIPs    []string `yaml:"link_local_ips,omitempty" json:"link_local_ips,omitempty"`
 	MacAddress      string   `yaml:"mac_address,omitempty" json:"mac_address,omitempty"`
-	DriverOpts      Options  `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
+	Priority        int      `yaml:"priority,omitempty" json:"priority,omitempty"`
 
 	Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
 }


Test patch:
diff --git a/loader/loader_test.go b/loader/loader_test.go
index fd21703..3af6aec 100644
--- a/loader/loader_test.go
+++ b/loader/loader_test.go
@@ -3820,3 +3820,18 @@ services:
 		Image:  &types.ServiceVolumeImage{SubPath: "/foo"},
 	})
 }
+
+func TestInterfaceName(t *testing.T) {
+	p, err := loadYAML(`
+name: interface-name
+services:
+  test:
+    networks:
+      test:
+        interface_name: eth0
+`)
+	assert.NilError(t, err)
+	assert.DeepEqual(t, p.Services["test"].Networks["test"], &types.ServiceNetworkConfig{
+		InterfaceName: "eth0",
+	})
+}