Skip to content

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

@jwendell

Description

@jwendell

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:

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
$ 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:

 $ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions