Merge pull request #1060 from tdgroot/podman_no_hosts_extension

Add x-podman.no_hosts extension
This commit is contained in:
Povilas Kanapickas 2024-10-14 18:05:25 +03:00 committed by GitHub
commit 4660feb04a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -14,6 +14,8 @@ The following extension keys are available under container configuration:
* `x-podman.rootfs` - Run the container without requiring any image management; the rootfs of the * `x-podman.rootfs` - Run the container without requiring any image management; the rootfs of the
container is assumed to be managed externally. container is assumed to be managed externally.
* `x-podman.no_hosts` - Run the container without creating /etc/hosts file
For example, the following docker-compose.yml allows running a podman container with externally managed rootfs. For example, the following docker-compose.yml allows running a podman container with externally managed rootfs.
```yml ```yml
version: "3" version: "3"

View File

@ -0,0 +1 @@
Add x-podman.no_hosts setting to pass --no-hosts to podman run

View File

@ -1254,6 +1254,8 @@ async def container_to_args(compose, cnt, detached=True):
podman_args.extend(["--uidmap", uidmap]) podman_args.extend(["--uidmap", uidmap])
for gidmap in cnt.get('x-podman.gidmaps', []): for gidmap in cnt.get('x-podman.gidmaps', []):
podman_args.extend(["--gidmap", gidmap]) podman_args.extend(["--gidmap", gidmap])
if cnt.get("x-podman.no_hosts", False):
podman_args.extend(["--no-hosts"])
rootfs = cnt.get('x-podman.rootfs', None) rootfs = cnt.get('x-podman.rootfs', None)
if rootfs is not None: if rootfs is not None:
rootfs_mode = True rootfs_mode = True

View File

@ -249,6 +249,25 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
], ],
) )
async def test_no_hosts_extension(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt["x-podman.no_hosts"] = True
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--no-hosts",
"busybox",
],
)
async def test_env_file_str(self): async def test_env_file_str(self):
c = create_compose_mock() c = create_compose_mock()