Skip to content

KeyError to network name #552

Closed
Closed

Description

@DevDorrejo

Describe the bug
Trying to execute the next composer code give "KeyError: 'postgres'":

version: "3"

services:
  postgres:
    container_name: PostgresSQL
    image: postgres
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
      PGDATA: /data/postgresql
    volumes:
      - postgresql:/data/postgresql
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: PgAdmin4
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL:
      PGADMIN_DEFAULT_PASSWORD:
    volumes:
      - pgadmin:/var/lib.pgadmin
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    networks:
      - postgres
    restart: unless-stopped

  networks:
    postgres:
      driver: bridge

  volumes:
    postgresql:
    pgadmin:

To Reproduce
Steps to reproduce the behavior:

  1. podman-compose -f postgresql.yml up (code above)

Output

$ podman-compose version
['podman', '--version', '']
using podman version: 4.2.0
podman-composer version  1.0.3
podman --version
podman version 4.2.0

$ podman-compose up
...
['podman', '--version', '']
using podman version: 4.2.0
** excluding:  set()
podman volume inspect db_postgresql || podman volume create db_postgresql
['podman', 'volume', 'inspect', 'db_postgresql']
Traceback (most recent call last):
File "/usr/bin/podman-compose", line 33, in <module>
sys.exit(load_entry_point('podman-compose==1.0.3', 'console_scripts', 'podman-compose')())
File "/usr/lib/python3.10/site-packages/podman_compose.py", line 1774, in main
podman_compose.run()
File "/usr/lib/python3.10/site-packages/podman_compose.py", line 1023, in run
cmd(self, args)
File "/usr/lib/python3.10/site-packages/podman_compose.py", line 1247, in wrapped
return func(*args, **kw)
File "/usr/lib/python3.10/site-packages/podman_compose.py", line 1414, in compose_up
podman_args = container_to_args(compose, cnt, detached=args.detach)
File "/usr/lib/python3.10/site-packages/podman_compose.py", line 644, in container_to_args
assert_cnt_nets(compose, cnt)
File "/usr/lib/python3.10/site-packages/podman_compose.py", line 557, in assert_cnt_nets
net_desc = nets[net] or {}
KeyError: 'postgres'

With 1.0.4 (pip3 install git+https://github.com/containers/podman-compose.git@9d5b2559274819e3b47230da85d4d306807bb4bf)

podman-compose version: 1.0.4
['podman', '--version', '']
using podman version: 4.2.0
Traceback (most recent call last):
File "/home/wedc/bin/DevTools/pipenv/bin/podman-compose", line 33, in <module>
sys.exit(load_entry_point('podman-compose==1.0.4', 'console_scripts', 'podman-compose')())
File "/home/wedc/bin/DevTools/pipenv/lib64/python3.10/site-packages/podman_compose.py", line 2852, in main
podman_compose.run()
File "/home/wedc/bin/DevTools/pipenv/lib64/python3.10/site-packages/podman_compose.py", line 1383, in run
self._parse_compose_file()
File "/home/wedc/bin/DevTools/pipenv/lib64/python3.10/site-packages/podman_compose.py", line 1530, in _parse_compose_file
raise RuntimeError(f"missing networks: {missing_nets_str}")
RuntimeError: missing networks: postgres

Environment:

  • OS: Linux / WSL / Mac: GNU/Linux openSUSE Tumbleweed
  • podman version: 4.2.0
  • podman compose version: (git hex) 1.0.3

Activity

  1. added
    bug
    on Sep 8, 2022
  2. mokibit commented on Aug 31, 2026

    @mokibit
    Collaborator

    I can reproduce this issue in the following environment:

    Debian GNU/Linux 13 (trixie)
    Python 3.13.5
    podman-compose version 1.6.0
    podman version 5.4.2
    

    I used the originally provided compose.yml, and the output of podman-compose up is the same as reported by the original user.
    However, after taking a closer look at compose.yml, the root cause seems to be invalid YAML indentation, not a bug in podman-compose.

    The networks and volumes keys in the reported compose.yml are indented at the same level as the service definitions (postgres, pgadmin), which means YAML parsers treat them as additional services named networks and volumes, rather than as top-level Compose keys.
    There is no top-level networks or volumes section, so when podman-compose tries to resolve the postgres network referenced by the real services, it raises RuntimeError: missing networks: postgres.

    On the other hand, docker-compose catches this with a schema validation error that is more descriptive (and podman-compose should behave similarly):

    $ docker-compose up -d
    validating .../docker-compose.yml: services.networks Additional property postgres is not allowed
    

    podman-compose does not perform schema validation, so it silently accepts networks and volumes as service names and only fails later when resolving network references.

    Solution: When networks and volumes are moved to the top level (i.e., not nested under services), the podman-compose up command works as expected.

    The podman-compose error message should be improved: it should detect that a service name is a reserved key (networks, volumes, secrets, configs) and emit a warning or a clearer error, similar to docker-compose's schema validation. I opened a dedicated issue for this: #1549.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions