Skip to content

Hardcoded PostgreSQL host port (25432) blocks running two environments in parallel #133

Description

@miguelCalado

Summary

composer-dev hardcodes the PostgreSQL host port to 25432, which makes it impossible to run two composer-dev environments concurrently when both use the postgresql database engine.

The resulting error message

Image

Problem

When starting a second environment while another one is already running, composer-dev start fails with:

Port 8090 is already in use. Please use different port or close application using port 8090.
You can select different port by using --port option when starting environment.

This message is misleading. The Airflow web server port (8090 in this example) is not actually in use - the user has already configured distinct port values in each environment's config.json. The real conflict is on port 25432, which both environments' PostgreSQL containers attempt to bind on the host.

Root cause: In composer_local_dev/environment.py, the DB host port is hardcoded:

# environment.py (Environment.database_extras)
"ports": {
    f"5432/tcp": "25432",
},

There is no CLI option or config.json field to override it, so every postgresql-backed environment competes for the same host port.

Proposed solution

  1. Make the PostgreSQL host port configurable.

    • Add an optional db_port field to config.json (default: 25432, preserving existing behavior).
    • Add a matching --db-port click option to create, start, and restart, mirroring the existing --web-server-port pattern.
    • Thread the value through EnvironmentConfig, Environment.__init__, load_from_config, and from_source_environment, and use it in database_extras in place of the hardcoded "25432".
  2. Fix the misleading error message. Inspect the Docker APIError to determine which host port was actually in conflict (web-server vs. DB) and format PORT_IN_USE_ERROR with the correct one. If detection isn't reliable, at minimum mention both candidate ports in the message.

This would unblock running multiple local environments concurrently (e.g. a test and a prod environment side-by-side) and give a clearer signal when a port conflict does occur.

Note: SQLite is file-based, so there's no container port to map, which can be an alternative here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions