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 <monika@kibit.lt>
This commit is contained in:
Monika Kairaityte
2025-07-20 20:59:43 +03:00
parent af7346baf6
commit 36fad25f25
2 changed files with 7 additions and 0 deletions

View File

@ -0,0 +1 @@
Implemented volumes bind `create_host_path` option.

View File

@ -405,6 +405,12 @@ async def assert_volume(compose: PodmanCompose, mount_dict: dict[str, Any]) -> N
mount_src = mount_dict["source"]
mount_src = os.path.realpath(os.path.join(basedir, os.path.expanduser(mount_src)))
if not os.path.exists(mount_src):
bind_opts = mount_dict.get("bind", {})
if "create_host_path" in bind_opts and not bind_opts["create_host_path"]:
raise ValueError(
"invalid mount config for type 'bind': bind source path does not exist: "
f"{mount_src}"
)
try:
os.makedirs(mount_src, exist_ok=True)
except OSError: