Home > Software design >  Internal Server Error when trying to connect to postgres container on Google Cloud Platform using Pg
Internal Server Error when trying to connect to postgres container on Google Cloud Platform using Pg

Time:04-17

I have deployed a postgres docker image using a cloudbuild.yaml file. My service is deployed on cloud run but I am not able to connect to the database using the url provided by the cloud run. I have included cloudbuild.yaml below.

- name: "gcr.io/cloud-builders/docker"
  args: ['pull', 'postgres']
- name: "gcr.io/cloud-builders/docker"
  args: ['tag', 'postgres','gcr.io/abi/postgres']
- name: "gcr.io/cloud-builders/docker"
  args: ['push', 'gcr.io/abi/postgres']  
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
  entrypoint: gcloud
  args: ['run', 'deploy','postgres', '--image','gcr.io/abi/postgres', '--region','us-central1','--platform','managed', '--port','5435', '--allow-unauthenticated','--set-env-vars','POSTGRES_USER=postgres','--set-env-vars','POSTGRES_PASSWORD=root','--set-env-vars','POSTGRES_DB=abi','--set-env-vars','PGDATA=/var/lib/postgresql/data','--set-env-vars','PGPORT=5435']

I also have the pgadmin image deployed and running on cloud run. I am getting an internal server error when I tried to add postgres database server to pgadmin using the URL provided by cloud run. Both the pgadmin and postgres images are deployed in the same project on GCP.

CodePudding user response:

The reason your container is crashing is that Google Cloud Run requires containers to respond to HTTP Requests.

Your container must listen on the configured TCP port, the default is 8080. The scheme is HTTP. Clients can connect to the Google Cloud Frontend using either HTTP (port 80) or HTTPS (port 443). HTTP requests will be redirected to HTTPS. In essence, your container must provide a web server. No other client protocols are supported such as FTP, SMTP, PostgreSQL, etc.

An additional problem for you is persistent data storage. How will you initialize the database files? Cloud Run can create and destroy a container at any time. Data is not persisted between container starts.

Container runtime contract

  • Related