Skip to content

Commit 98d9539

Browse files
committed
Implement volumes bind.create_host_path option
The `type:bind` volume option `create_host_path` is currently unsupported in `podman-compose`. This prevents users from disabling the automatic creation of host source directories, creating an incompatibility with `docker-compose` functionality. Refer to the relevant `docker-compose` documentation: https://docs.docker.com/reference/compose-file/services/#volumes This commit implements the `create_host_path` option to: - Achieve better alignment with `docker-compose` behavior - Provide control over host directory creation Signed-off-by: Monika Kairaityte <[email protected]>
1 parent 036c0dc commit 98d9539

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implemented volumes bind `create_host_path` option.

podman_compose.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,17 @@ async def assert_volume(compose: PodmanCompose, mount_dict: dict[str, Any]) -> N
405405
mount_src = mount_dict["source"]
406406
mount_src = os.path.realpath(os.path.join(basedir, os.path.expanduser(mount_src)))
407407
if not os.path.exists(mount_src):
408-
try:
409-
os.makedirs(mount_src, exist_ok=True)
410-
except OSError:
411-
pass
408+
bind_opts = mount_dict.get("bind", {})
409+
if "create_host_path" in bind_opts and not bind_opts["create_host_path"]:
410+
raise ValueError(
411+
"invalid mount config for type 'bind': bind source path does not exist: "
412+
+ "{mount_src}"
413+
)
414+
else:
415+
try:
416+
os.makedirs(mount_src, exist_ok=True)
417+
except OSError:
418+
pass
412419
mount_dict["source"] = mount_src
413420
return
414421
if mount_dict["type"] != "volume" or not vol or not vol.get("name"):

0 commit comments

Comments
 (0)