the-bed-stack
the-bed-stack copied to clipboard
Dev container does not support custom DB ports
Version
latest
Describe the bug
The devcontainer does not support changing the DB port to something other than 5432.
Reproduction
- Occupy port 5432 with something.
- Change the DB port to 5431 in
.env
. - Rebuild the devcontainer.
- You will get an ECONREFUSED error in the console.
System Info
Macbook Air M2
Validations
- [X] Read the Contributing Guidelines.
- [X] Check that there isn't already an issue that reports the same bug.
- [X] Check that this is a concrete bug. For Q&A, open a GitHub Discussion.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Wait, isn't this because of how we do the port mapping in docker compose? It looks like this:
ports:
- ${POSTGRES_PORT}:5432
which means if you update the .env file, then the 5432 port inside the container will be mapped to a different port in your host machine. But the problem is that the app will try to connect to POSTGRES_PORT inside the container, because it's using that env var.
I think something like this would solve it:
ports:
- ${POSTGRES_PORT}:${POSTGRES_PORT}
& we need to add the POSGRES_PORT env var to the environment
key too:
db:
image: postgres:16
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_PORT=${POSTGRES_PORT}
healthcheck:
test:
[
"CMD",
"pg_isready",
"-U",
"${POSTGRES_USER}",
]
interval: 5s
timeout: 30s
retries: 10
# This allows accessing externally from "localhost" in addition to "127.0.0.1"
ports:
- ${POSTGRES_PORT}:${POSTGRES_PORT}