How to connect to a Postgres DB (running in a container not installed locally)? #30880
Replies: 1 comment
-
Hey there, @petervatler! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together! To connect Superset to a Postgres database running in a Docker container without opening the 5433 port, you can leverage Docker's internal networking. Since both Superset and the Postgres database are on the same Docker network, you should use the service name of the Postgres container as the host in your connection string. Here's how you can do it:
Here's an example connection string: SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@postgres:5433/dbname' Replace This approach uses Docker's internal DNS to resolve the service name to the correct container IP, allowing communication without exposing ports to the host machine [1]. |
Beta Was this translation helpful? Give feedback.
-
I'd like to run the Superset app and a Postgres engine in containers. I built a docker-compose to do this. The only way it works if I open the 5433 port like if I wanted to reach the Postgres database from my host machine. The superset app and the Postgres engine are on the same Docker network although Superset can't connect to it. It wants to connect through host.docker.internal. I also overwrote the default 5432 Postgres port to 5433.
Do I need another Docker network type? Or should I set any environment variable for Superset? Although it works on 5433 if I open the port but I don't want to necessarily open it.
The other thing I tried is setting the DATABASE_HOST env variable for superset to the service name, it started up, I could log in but nothing could load inside Superset, I mean I had empty charts and dashboards. It showed error on every item with the same issue I had before it really wants to join through host.docker.internal.
Beta Was this translation helpful? Give feedback.
All reactions