From b55250b10597940b3594687733f3b92a1783807e Mon Sep 17 00:00:00 2001 From: Bas Zoetekouw Date: Thu, 21 Mar 2024 19:42:05 +0100 Subject: [PATCH] Support and document all podman-specific network_modes Signed-off-by: Bas Zoetekouw --- docs/Extensions.md | 20 ++++++++++++++++++++ podman_compose.py | 7 ++++++- pytests/test_get_net_args.py | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/Extensions.md b/docs/Extensions.md index a5388220..6d9af730 100644 --- a/docs/Extensions.md +++ b/docs/Extensions.md @@ -45,3 +45,23 @@ services: ipv4_address: "192.168.1.10" podman.mac_address: "02:bb:bb:bb:bb:bb" ``` + +## Podman-specific network modes + +Generic docker-compose supports the following values for `network-mode` for a container: + +- `bridge` +- `host` +- `none` +- `service` +- `container` + +In addition, podman-compose supports the following podman-specific values for `network-mode`: + +- `slirp4netns[:,...]` +- `ns:` +- `pasta[:,...]` +- `private` + +The options to the network modes are passed to the `--network` option of the `podman create` command +as-is. diff --git a/podman_compose.py b/podman_compose.py index 39e23964..90001846 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -768,7 +768,11 @@ def get_net_args(compose, cnt): net_args.append(f"--network={net}") elif net.startswith("slirp4netns"): # Note: podman-specific network mode net_args.append(f"--network={net}") - elif net.startswith("ns:"): + elif net == "private": # Note: podman-specific network mode + net_args.append("--network=private") + elif net.startswith("pasta"): # Note: podman-specific network mode + net_args.append(f"--network={net}") + elif net.startswith("ns:"): # Note: podman-specific network mode net_args.append(f"--network={net}") elif net.startswith("service:"): other_srv = net.split(":", 1)[1].strip() @@ -788,6 +792,7 @@ def get_net_args(compose, cnt): default_net = compose.default_net nets = compose.networks cnt_nets = cnt.get("networks", None) + aliases = [service_name] # NOTE: from podman manpage: # NOTE: A container will only have access to aliases on the first network diff --git a/pytests/test_get_net_args.py b/pytests/test_get_net_args.py index ca149bd4..6a9fc5c7 100644 --- a/pytests/test_get_net_args.py +++ b/pytests/test_get_net_args.py @@ -261,7 +261,10 @@ def test_mixed_config(self): ("none", []), ("slirp4netns", ["--network=slirp4netns"]), ("slirp4netns:cidr=10.42.0.0/24", ["--network=slirp4netns:cidr=10.42.0.0/24"]), + ("private", ["--network=private"]), + ("pasta", ["--network=pasta"]), ("pasta:--ipv4-only,-a,10.0.2.0", ["--network=pasta:--ipv4-only,-a,10.0.2.0"]), + ("ns:my_namespace", ["--network=ns:my_namespace"]), ("container:my_container", ["--network=container:my_container"]), ]) def test_network_modes(self, network_mode, expected_args):