Skip to content

Commit 90f54b9

Browse files
committed
Add x-podman.no_hosts extension
Signed-off-by: Timon de Groot <[email protected]>
1 parent 7090de3 commit 90f54b9

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

docs/Extensions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The following extension keys are available under container configuration:
1414
* `x-podman.rootfs` - Run the container without requiring any image management; the rootfs of the
1515
container is assumed to be managed externally.
1616

17+
* `x-podman.no_hosts` - Run the container without creating /etc/hosts file
18+
1719
For example, the following docker-compose.yml allows running a podman container with externally managed rootfs.
1820
```yml
1921
version: "3"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add x-podman.no_hosts setting to pass --no-hosts to podman run

podman_compose.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,8 @@ async def container_to_args(compose, cnt, detached=True):
12541254
podman_args.extend(["--uidmap", uidmap])
12551255
for gidmap in cnt.get('x-podman.gidmaps', []):
12561256
podman_args.extend(["--gidmap", gidmap])
1257+
if cnt.get("x-podman.no_hosts", False):
1258+
podman_args.extend(["--no-hosts"])
12571259
rootfs = cnt.get('x-podman.rootfs', None)
12581260
if rootfs is not None:
12591261
rootfs_mode = True

tests/unit/test_container_to_args.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@ async def test_rootfs_extension(self):
249249
],
250250
)
251251

252+
async def test_no_hosts_extension(self):
253+
c = create_compose_mock()
254+
255+
cnt = get_minimal_container()
256+
cnt["x-podman.no_hosts"] = True
257+
258+
args = await container_to_args(c, cnt)
259+
self.assertEqual(
260+
args,
261+
[
262+
"--name=project_name_service_name1",
263+
"-d",
264+
"--network=bridge",
265+
"--network-alias=service_name",
266+
"--no-hosts",
267+
"busybox",
268+
],
269+
)
270+
252271
async def test_env_file_str(self):
253272
c = create_compose_mock()
254273

0 commit comments

Comments
 (0)