Add env-var interpolation to docker-compose ports#495
Conversation
Allow unique host ports via POSTGRES_PORT/REDIS_PORT env vars with 5432/6379 defaults so multiple projects can run simultaneously.
There was a problem hiding this comment.
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.
| POSTGRES_PORT=5432 | ||
| REDIS_PORT=6379 |
There was a problem hiding this comment.
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}.
| image: redis:6-alpine | ||
| ports: | ||
| - '127.0.0.1:6379:6379' | ||
| - "127.0.0.1:${REDIS_PORT:-6379}:6379" |
There was a problem hiding this comment.
|
|
||
| ### 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`. |
Allow unique host ports via
POSTGRES_PORT/REDIS_PORTenv vars with 5432/6379 defaults so multiple projects can run simultaneously.Changes
${POSTGRES_PORT:-5432}:5432and${REDIS_PORT:-6379}:6379POSTGRES_PORT=5432andREDIS_PORT=6379defaultsImpact
Zero impact for existing developers — defaults are unchanged.