From 36fad25f25c34935a8c8381c413c53d39159c27d Mon Sep 17 00:00:00 2001 From: Monika Kairaityte Date: Sun, 20 Jul 2025 20:59:43 +0300 Subject: [PATCH] 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 --- .../add-volumes-bind-create-host-path-option.bugfix | 1 + podman_compose.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 newsfragments/add-volumes-bind-create-host-path-option.bugfix diff --git a/newsfragments/add-volumes-bind-create-host-path-option.bugfix b/newsfragments/add-volumes-bind-create-host-path-option.bugfix new file mode 100644 index 0000000..1c0d9f6 --- /dev/null +++ b/newsfragments/add-volumes-bind-create-host-path-option.bugfix @@ -0,0 +1 @@ +Implemented volumes bind `create_host_path` option. diff --git a/podman_compose.py b/podman_compose.py index e627923..b4b24d5 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -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: