Friday, August 4, 2017

[google-cloud-sql-discuss] Re: Unable to connect to Cloud-SQL proxy Docker Image

Hi Vadim,

Thanks for your email.

Here's my db section in the docker compose file referencing the cloud proxy:

db:

    image: gcr.io/cloudsql-docker/gce-proxy:1.10

    read_only: true

    tmpfs:

      - /tmp

      - /var/run/postgresql

    volumes:

      - ./config/QwikGiving-d57xxxxxx.json:/xxxx-d57xxxxxx.json

      - db:/var/lib/postgresql/data

      - ./config/postgres-initdb.sh:/docker-entrypoint-initdb.d/initdb.sh

    ports:

      # - '5432:5432'

      - '127.0.0.1:5435:5432'

    command: ./cloud_sql_proxy -dir=/cloudsql -instances=xxxxxx-xxxxx:europe-west1:dbxxxx=tcp:5432 -credential_file=xxxxxxx-xxxx.json



After running the docker container, we were ready for new connections, here's the log: 

db_1     | 2017/08/04 21:54:55 using credential file for authentication; email=thexxx-proxy@xxxxxx-1xxxxx.iam.gserviceaccount.com
db_1     | 2017/08/04 21:54:55 Listening on 127.0.0.1:5435 for xxxx-xxxx:europe-west1:dbxxxx
db_1     | 2017/08/04 21:54:55 Ready for new connections

So with the above, you can see the cloud_sql proxy image was successfully configured. So in my NodeJS application, I passed something like this for connection params:

const config = new Sequelize(process.env.DATABASE_URL);


Where process,env,DATABASE_URL was passed as environment variables, here's it was passed:

- DATABASE_URL=postgres://username:password@127.0.0.1:5432/db

Hope the above helps in understanding my setup. Please let me know if you have follow on questions.

Thanks,
Kunle

On Friday, 4 August 2017 23:12:12 UTC+1, Ife A wrote:
Hi there,

Have been struggling with this issue for the past three days and even put a support ticket forward but not much progress, so far its been quite frustrating. Enough of my ranting, here goes the issue / scenario:

I have a NodeJS application with postgres database which I put in a docker container called `api`. I have a docker-compose file that automatically builds my applications in a docker container and then push them into GCP  VM. So have got 1) Api docker image, 2) db docker image which was built using Cloud_SQL Proxy image, 3) redis 4) nginx - all docker images. 
When I use just my local postgres database placed in a docker container under the base docker image `postgres:9.6.3-alpine`. I was able to connect fine to my NodeJS application but keep getting `Connection Refused` when I use `gcr.io/cloudsql-docker/gce-proxy:1.10` cloud-sql image.

So the issue is, my NodeJS application (api docker) is unable to connect to the `db` cloud_sql docker image. Not sure how to best resolve this, please assist. Kindly suggest if there are more feasible way to connect to my postgres inside from a docker container (api docker) on GCP.

Thanks in anticipation,

Ife

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/45c6d72e-a0e9-46ef-a836-6b95fedd989b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment