无法连接到Google Cloud上的Postgres数据库实例

时间:2020-07-22 03:10:48

标签: postgresql docker sqlalchemy gcloud

我无法连接到Google Cloud上的数据库。 在我的Dockerfile中,我正在调用python脚本以连接到数据库,如下所示:

Dockerfile:

....
ADD script.py /home/script.py
CMD ["/home/script.py"]
ENTRYPOINT ["python"]

Python脚本

import sqlalchemy as db
# x.x.x.x is the public ip of the database instance
engine = db.create_engine('postgresql+psycopg2://user:db_pass@x.x.x.x/db_name')
connection = engine.connect()
metadata = db.MetaData()
experiments = db.Table('experiments', metadata, autoload=True, autoload_with=engine)

但是我一直收到此错误:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Operation timed out
          Is the server running on host "x.x.x.x" and accepting
          TCP/IP connections on port 5432?

有人可以帮助我吗?谢谢!!

0 个答案:

没有答案
相关问题