Skip to content

Add env-var interpolation to docker-compose ports#495

Draft
tp-abtion wants to merge 1 commit into
mainfrom
docker-compose-unique-ports
Draft

Add env-var interpolation to docker-compose ports#495
tp-abtion wants to merge 1 commit into
mainfrom
docker-compose-unique-ports

Conversation

@tp-abtion
Copy link
Copy Markdown
Contributor

Allow unique host ports via POSTGRES_PORT/REDIS_PORT env vars with 5432/6379 defaults so multiple projects can run simultaneously.

Changes

  • docker-compose.yml: Replace hardcoded ports with ${POSTGRES_PORT:-5432}:5432 and ${REDIS_PORT:-6379}:6379
  • .env: Add POSTGRES_PORT=5432 and REDIS_PORT=6379 defaults
  • README.md: Add "Custom Docker Ports" section

Impact

Zero impact for existing developers — defaults are unchanged.

Allow unique host ports via POSTGRES_PORT/REDIS_PORT env vars with
5432/6379 defaults so multiple projects can run simultaneously.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for custom Docker ports for Postgres and Redis by adding environment variables to .env and updating the docker-compose.yml configuration. Documentation has been added to the README to explain this new capability. The review feedback identifies potential issues: the application's connection strings in .env remain hardcoded and should use variable expansion to stay in sync with the new port variables, the smtp4dev service ports should also be parameterized to prevent conflicts, and the documentation should explicitly clarify that changing ports requires corresponding updates to the application's connection strings.

Comment thread .env
Comment on lines +4 to +5
POSTGRES_PORT=5432
REDIS_PORT=6379
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding these variables allows for Docker port customization, the connection strings DATABASE_SERVER (line 6) and REDIS_URL (line 13) still have hardcoded ports. If a developer changes the port variables, the application will fail to connect because it will still look for the services on the default ports. Consider using variable expansion within the .env file to keep them in sync, for example: DATABASE_SERVER=postgres://postgres:@127.0.0.1:${POSTGRES_PORT}.

Comment thread docker-compose.yml
image: redis:6-alpine
ports:
- '127.0.0.1:6379:6379'
- "127.0.0.1:${REDIS_PORT:-6379}:6379"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To fully support running multiple projects simultaneously as intended, the smtp4dev service ports (lines 20-21) should also be parameterized. Currently, they are hardcoded to 5000 and 2525, which will cause port conflicts if another instance of this template is running on the same host.

Comment thread README.md

### Custom Docker Ports

Docker services bind to default ports (Postgres 5432, Redis 6379). To use custom host ports (e.g. to run multiple projects simultaneously), set `POSTGRES_PORT` and/or `REDIS_PORT` in `.env.local` and make sure they're exported before running `docker compose`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is important to clarify that changing these ports also requires updating the application's connection strings in the .env file, otherwise the app will not be able to reach the database or Redis.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant