postgresqldockerdockerfilegoogle-cloud-sqldocker-image

Unable to pip install google.cloud.sql.connector when building docker image


I am using Python developing a web app in my local machine. I am using the code from Connect using Cloud SQL Language Connectors to connect to my GCP Postgres database and working fine! However, when I building the docker image using docker file, I failed at the step of "RUN pip install google-cloud-sql-connector" which is the connector that I use in my coding in order to connect to GCP Postgres.

The error shows as below:

# [13/13] RUN pip install google-cloud-sql-connector:
# 0.911 ERROR: Could not find a version that satisfies the requirement google-cloud-sql-connector    (from versions: none)
# 0.911 ERROR: No matching distribution found for google-cloud-sql-connector
# # ------
# ****Dockerfile:15
# # --------------------**
# 13 | RUN pip install pg8000
# 14 | RUN pip install google-cloud-secret-manager
# 15 | >>> RUN pip install google-cloud-sql-connector
# 16 | CMD ["python","main.py"]
# 17 |
# # --------------------**
# ERROR: failed to solve: process "/bin/sh -c pip install google-cloud-sql-connector" did not complete successfully: exit code: 1

Please can anyone of you help? Thank you.

Help to resolve the error


Solution

  • There are two different database drivers that are supported for the Postgres dialect.

    pg8000

    pip install "cloud-sql-python-connector[pg8000]"
    

    asyncpg

    pip install "cloud-sql-python-connector[asyncpg]"
    

    here is the details