Merge pull request #1147 from joern19/main

Allow configuration of interface_name
This commit is contained in:
Povilas Kanapickas 2025-02-24 01:26:38 +02:00 committed by GitHub
commit 07af8488db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 78 additions and 1 deletions

View File

@ -86,7 +86,7 @@ networks:
- subnet: "192.168.1.0/24"
services:
webserver
webserver:
image: "busybox"
command: ["/bin/busybox", "httpd", "-f", "-h", "/etc", "-p", "8001"]
networks:
@ -98,6 +98,10 @@ services:
mac_address: "02:bb:bb:bb:bb:bb" # mac_address is supported
```
## Per-network interface name
Using `x-podman.interface_name` within a containers network config you can specify the interface name inside the container.
## Podman-specific network modes
Generic docker-compose supports the following values for `network-mode` for a container:

View File

@ -0,0 +1 @@
- Add support for 'x-podman.interface_name' to allow setting the interface name for each network participation.

View File

@ -989,6 +989,7 @@ def get_net_args_from_networks(compose, cnt):
default_net_name = default_network_name_for_project(compose, net_, is_ext)
net_name = ext_desc.get("name") or net_desc.get("name") or default_net_name
interface_name = net_config_.get("x-podman.interface_name")
ipv4 = net_config_.get("ipv4_address")
ipv6 = net_config_.get("ipv6_address")
# Note: mac_address is supported by compose spec now, and x-podman.mac_address
@ -1006,6 +1007,8 @@ def get_net_args_from_networks(compose, cnt):
mac_address = None
net_options = []
if interface_name:
net_options.append(f"interface_name={interface_name}")
if ipv4:
net_options.append(f"ip={ipv4}")
if ipv6:

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,10 @@
version: "3"
networks:
mystack:
services:
web:
image: busybox
command: ["/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8004"]
networks:
mystack:
x-podman.interface_name: customName0

View File

@ -0,0 +1,58 @@
# SPDX-License-Identifier: GPL-2.0
# pylint: disable=redefined-outer-name
import os
import unittest
from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path
class TestPodmanComposeNetworkInterfaceName(RunSubprocessMixin, unittest.TestCase):
def compose_file(self):
return os.path.join(test_path(), "network_interface_name", "docker-compose.yml")
def up(self):
up_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
self.compose_file(),
"up",
"-d",
"--force-recreate",
]
self.run_subprocess_assert_returncode(up_cmd)
def down(self):
down_cmd = [
"coverage",
"run",
podman_compose_path(),
"-f",
self.compose_file(),
"kill",
"-a",
]
self.run_subprocess(down_cmd)
def test_interface_name(self):
try:
self.up()
interfaces_cmd = [
podman_compose_path(),
"-f",
self.compose_file(),
"exec",
"web",
"ls",
"/sys/class/net",
"--color=never",
]
out, _ = self.run_subprocess_assert_returncode(interfaces_cmd)
self.assertEqual("customName0 lo\r\n", out.decode())
finally:
self.down()