Skip to content

Commit 9be3ec9

Browse files
committed
Add network "dns" support
This patch add 'x-podman.dns' option to the 'network' configuration, allowing users to set the DNS resolvers for a defined network. Signed-off-by: Rafael Guterres Jeffman <[email protected]>
1 parent 6e642dc commit 9be3ec9

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

Diff for: docs/Extensions.md

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ For explanations of these extensions, please refer to the [Podman Documentation]
3232
The following extension keys are available under network configuration:
3333
3434
* `x-podman.disable-dns` - Disable the DNS plugin for the network when set to 'true'.
35+
* `x-podman.dns` - Set nameservers for the network using supplied addresses (cannot be used with x-podman.disable-dns`).
36+
37+
For example, the following docker-compose.yml allows all containers on the same network to use the
38+
specified nameservers:
39+
```yml
40+
version: "3"
41+
network:
42+
my_network:
43+
x-podman.dns:
44+
- "10.1.2.3"
45+
- "10.1.2.4"
46+
```
3547

3648
For explanations of these extensions, please refer to the
3749
[Podman network create command Documentation](https://docs.podman.io/en/latest/markdown/podman-network-create.1.html).

Diff for: newsfragments/x-podman.dns.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add support for 'x-podman.dns' to allow setting DNS nameservers for defined networks.

Diff for: podman_compose.py

+5
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,11 @@ def get_network_create_args(net_desc, proj_name, net_name):
835835
args.append("--ipv6")
836836
if net_desc.get("x-podman.disable_dns"):
837837
args.append("--disable-dns")
838+
if net_desc.get("x-podman.dns"):
839+
args.extend((
840+
"--dns",
841+
",".join(norm_as_list(net_desc.get("x-podman.dns"))),
842+
))
838843

839844
if isinstance(ipam_config_ls, dict):
840845
ipam_config_ls = [ipam_config_ls]

Diff for: tests/unit/test_get_network_create_args.py

+50
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,53 @@ def test_disable_dns(self):
225225
]
226226
args = get_network_create_args(net_desc, proj_name, net_name)
227227
self.assertEqual(args, expected_args)
228+
229+
def test_dns_string(self):
230+
net_desc = {
231+
"labels": [],
232+
"internal": False,
233+
"driver": None,
234+
"driver_opts": {},
235+
"ipam": {"config": []},
236+
"enable_ipv6": False,
237+
"x-podman.dns": "192.168.1.2",
238+
}
239+
proj_name = "test_project"
240+
net_name = "test_network"
241+
expected_args = [
242+
"create",
243+
"--label",
244+
f"io.podman.compose.project={proj_name}",
245+
"--label",
246+
f"com.docker.compose.project={proj_name}",
247+
"--dns",
248+
"192.168.1.2",
249+
net_name,
250+
]
251+
args = get_network_create_args(net_desc, proj_name, net_name)
252+
self.assertEqual(args, expected_args)
253+
254+
def test_dns_list(self):
255+
net_desc = {
256+
"labels": [],
257+
"internal": False,
258+
"driver": None,
259+
"driver_opts": {},
260+
"ipam": {"config": []},
261+
"enable_ipv6": False,
262+
"x-podman.dns": ["192.168.1.2", "192.168.1.3"],
263+
}
264+
proj_name = "test_project"
265+
net_name = "test_network"
266+
expected_args = [
267+
"create",
268+
"--label",
269+
f"io.podman.compose.project={proj_name}",
270+
"--label",
271+
f"com.docker.compose.project={proj_name}",
272+
"--dns",
273+
"192.168.1.2,192.168.1.3",
274+
net_name,
275+
]
276+
args = get_network_create_args(net_desc, proj_name, net_name)
277+
self.assertEqual(args, expected_args)

0 commit comments

Comments
 (0)