Skip to content

Commit

Permalink
Support and document all podman-specific network_modes
Browse files Browse the repository at this point in the history
Signed-off-by: Bas Zoetekouw <bas.zoetekouw@surf.nl>
  • Loading branch information
baszoetekouw committed Mar 28, 2024
1 parent 3fca21f commit b55250b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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[:<options>,...]`
- `ns:<options>`
- `pasta[:<options>,...]`
- `private`

The options to the network modes are passed to the `--network` option of the `podman create` command
as-is.
7 changes: 6 additions & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pytests/test_get_net_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b55250b

Please sign in to comment.