containers / containers/podman-compose
Volume definition required for single use volumes
- Dominant language
- Python
- Stars
- 6.2k
- Forks
- 622
- PR merge metrics
- No merged PRs in 30d
Description
**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](https://github.com/compose-spec/compose-spec/blob/master/spec.md#volumes) 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:
1. 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
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
Contributor guide
Assessment
This issue has not been assessed yet.