Cannot connect to timescale when port isn't 5432
bsidelinger912 opened this issue · 3 comments
Describe the bug
Using the docker-compose example, when I map timescale's container's port 5432 (5431:5432 for example) to another port then promscale cannot connect. If I change it back to 5432 everything works fine. When I'm exposing timescaledb under port 5431 I can connect just fine to it using psql, so I'm pretty sure the port mapping is working fine. I've tried using both the PROMSCALE_DB_URI as well as specifying all the DB_ env variables and the results are exactly the same either way.
To Reproduce
Use this docker-compose, you'll see that promscale fails to connect
version: "3"
services:
prometheus:
restart: always
image: prom/prometheus:v2.39.1
ports:
- "9090:9090"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: bind
source: ${PWD}/prometheus.yml
target: /etc/prometheus/prometheus.yml
depends_on:
- promscale
timescaledb:
image: timescale/timescaledb-ha:pg14-latest
restart: on-failure
ports:
- 5431:5432/tcp
volumes:
- timescaledb-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_DB: tsdb
POSTGRES_HOST_AUTH_METHOD: trust
promscale:
image: timescale/promscale:latest
restart: on-failure
ports:
- 9201:9201/tcp
- 9202:9202/tcp
depends_on:
- timescaledb
environment:
PROMSCALE_DB_HOST: timescaledb
PROMSCALE_DB_PASSWORD: password
PROMSCALE_DB_SSL_MODE: allow
PROMSCALE_DB_NAME: tsdb
PROMSCALE_DB_PORT: 5431
volumes:
timescaledb-data:
Modify the docker compose like so, and you'll see that promscale connects just fine:
version: "3"
services:
prometheus:
restart: always
image: prom/prometheus:v2.39.1
ports:
- "9090:9090"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: bind
source: ${PWD}/prometheus.yml
target: /etc/prometheus/prometheus.yml
depends_on:
- promscale
timescaledb:
image: timescale/timescaledb-ha:pg14-latest
restart: on-failure
ports:
- 5432:5432/tcp
volumes:
- timescaledb-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_DB: tsdb
POSTGRES_HOST_AUTH_METHOD: trust
promscale:
image: timescale/promscale:latest
restart: on-failure
ports:
- 9201:9201/tcp
- 9202:9202/tcp
depends_on:
- timescaledb
environment:
# PROMSCALE_DB_URI: postgres://postgres:password@timescaledb:5432/tsdb?sslmode=allow
PROMSCALE_DB_HOST: timescaledb
PROMSCALE_DB_PASSWORD: password
PROMSCALE_DB_SSL_MODE: allow
PROMSCALE_DB_NAME: tsdb
PROMSCALE_DB_PORT: 5432
volumes:
timescaledb-data:
Expected behavior
I'd expect that promscale would connect just fine on port 5431. Also, I've used the same setup with timescale cloud, passing the full url for the timescale cloud service and it all works just fine, so I'm only seeing this when I run timescale in the same docker-compose as promscale.
Configuration (as applicable)
This should be covered by the above docker-compose examples
Version
- Distribution/OS: Mac M1
- Promscale: latest from docker hub
- TimescaleDB: latest from docker hub
Additional context
The reason I want to change the port is that we already have a regular postgres database running on port 5432 that we use for our general business logic. In production we're using timescale cloud for metrics data and that is working great. We just don't want to use timescale cloud for local development and e2e tests, due to the need for an isolated environment. One option I thought of is to just use the same timescale db server instance for all of our other business logic as well, any advice on the best setup?
I'm not in front of my computer right now so can't test but I believe Docker Compose creates a separate network for the different containers. So you can change the localhost port mapping for TimescaleDB to avoide the port conflict but you should leave the original port in the promscale container configuration.
Regarding your other question. Could you share more about your use case and amount of data ingest? In general it's better to keep business data and observability data separated so the later does not impact the former but there are cases where it would make sense to cobine them.
Oh, and thank you so much for the detailed description of the issue!
Thanks for the response @ramonguiu! You're totally right, I was mixing external networking with internal networking in Docker, it works fine doing it as you described.