containers / containers/podman-compose

RuntimeError: volume ["/a_dir_from_env"] not defined in top level

Open
#1,318 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Python
Stars
6.2k
Forks
622
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Wrong parsing of a compose file leads to an error preventing the container to start, whereas it's parsed fine in docker-compose.

**To Reproduce**
Given this small compose file:
```yaml
services:
a_test:
image: alpine:latest
environment:
- A_DIR="${A_DIR:-/a_dir_from_env}"
command: ["sh", "-c", "echo 'This is a test container.' && sleep 3600"]
volumes:
- ${A_DIR:-/tmp/a_dir_from_volume}:/a_dir
```

```sh
$ podman_compose.py -f bug-compose.yml run --rm a_test
File "/home/jwendell/src/others/podman-compose/podman_compose.py", line 2529, in _parse_compose_file
raise RuntimeError(f"volume [{vol_name}] not defined in top level")
RuntimeError: volume ["/a_dir_from_env"] not defined in top level
```

AFAICT, the parser is considering the environment variable defined within `environment:` section to populate the variable in the `volumes:` section.

Using docker-compose, the container successfully starts and uses the host's dir `/tmp/a_dir_from_volume` as the source, and sets the variable correctly:
```sh
$ docker exec -it ci-a_test-run-a7a3f5c654b8 sh
/ # echo $A_DIR
"/a_dir_from_env"
/ #
```

I'm using podman-compose main branch as of today on Fedora 42.

Contributor guide

Open the contributing guide

Research direction

Start in podman_compose.py at _parse_compose_file around line 2529 and reproduce the failure with the compose file shown in the issue. Trace how environment and volume substitutions are parsed, then verify that the volume uses /tmp/a_dir_from_volume while the container environment retains "/a_dir_from_env" and the container starts successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.