Volume definition required for single use volumes
Describe the bug
Podman-compose always requires volume labels to be defined in the top-level config, otherwise it will stop and give the error RuntimeError: volume [volume_name] not defined in top level. This is wrong, since the spec says this is not needed for volumes that are used in a single service:
If the mount is a host path and is only used by a single service, it can be declared as part of the service definition. To reuse a volume across multiple services, a named volume must be declared in the [top-level volumes key](https://github.com/compose-spec/compose-spec/blob/master/07-volumes.md).
To Reproduce Steps to reproduce the behavior:
- Try to run a docker-compose.yml with volume labels such as the following:
services:
frontend:
image: busybox
volumes:
- testdir:/home/user:z
Expected behavior It runs
Actual behavior
It gives the error RuntimeError: volume [testdir] not defined in top level. Adding the following fixes the error. But this should not be required.
volumes:
testdir:
Output
$ podman-compose version
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.6.1
podman-compose version 1.0.6
podman --version
podman version 4.6.1
exit code: 0
$ podman-compose up
...
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.6.1
Traceback (most recent call last):
File "/usr/bin/podman-compose", line 33, in <module>
sys.exit(load_entry_point('podman-compose==1.0.6', 'console_scripts', 'podman-compose')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/podman_compose.py", line 2940, in main
podman_compose.run()
File "/usr/lib/python3.11/site-packages/podman_compose.py", line 1420, in run
self._parse_compose_file()
File "/usr/lib/python3.11/site-packages/podman_compose.py", line 1627, in _parse_compose_file
raise RuntimeError(
RuntimeError: volume [testdir] not defined in top level
Environment:
- OS: Linux
- podman version: 4.6.1
- podman compose version: 1.0.6
Additional context
The bug is introduced in https://github.com/containers/podman-compose/commit/154a51245ff2c5c8c3690d3a0035b710b69d0c3d.
ref: #746
Just found this issue, but I think is to be happen this way.
when you use
volumes:
abc_data:
services:
abc:
volumes:
- abc_data:/data
You are telling you want a external volume which can be shared with other service. Now if you only want use a directory as volume, you need do:
# volumes:
# abc_data:
services:
abc:
volumes:
- ./abc_data:/data
You need inform you are using a filesystem structure, using ./ as a directory in the current path, or just use a full path.