Connection to Google Cloud SQL via proxy works in all scenarios except via socket in Docker container

11/10/2017

Hopefully I'm doing something wrong, I've read all documentation and scoured forums but can't seem to get to the bottom of an issue I'm experiencing. I'm using OSX btw.

Things that are working:

  1. Connect to cloud SQL from local OS using proxy via either TCP or Socket
  2. Connect to cloud SQL from local OS using proxy in container via TCP
  3. Connect to cloud SQL from GKE using proxy in the same pod via TCP

Things that are not working:

  1. Connect to cloud SQL from local OS using proxy in contain via sockets
  2. Connect to cloud SQL from GKE using proxy in the same pod via socket

I suspect both of these problems are actually the same problem. I'm using this command to run the proxy inside of the container:

docker run -v [PATH]:/cloudsql \ 
gcr.io/cloudsql-docker/gce-proxy /cloud_sql_proxy -dir=/cloudsql \ 
-instances=[INSTANCE_CONNECTION_NAME] -credential_file=/cloudsql/[FILE].json

And the associated socket is being generated with the directory. However when I attempt to connect I get the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/cloudsql/node-sql:us-central1:nodedb' (61)

The proxy doesn't generate a new line when I try to connect which makes me think that it's not receiving the request, it simply says Ready for new connections and waits.

Any idea what's going wrong, or how I could troubleshoot this further?

-- Wes Nolte
google-cloud-sql
google-kubernetes-engine

1 Answer

1/2/2018

For "Connect to cloud SQL from GKE using proxy in the same pod via socket" can you please follow the tutorial at https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine? We have a working WordPress example there that has the cloudsql-proxy as a sidecar container (i.e. in the same Pod, but over TCP).

I don't think you can do "in the same pod via socket" unless you’re running multiple processes in a single container (which you shouldn’t as a best practice). If you do a sidecar container, you can use TCP, so you don’t need a unix socket (moreover, I'm not sure how you’d share files between containers of a Pod).

Also, the docker run -v /local.sock:/remote.sock (I think) will be creating a file/directory locally as /local.sock and making that available inside the container as /remote.sock. This might not work because the docker-engine doesn't know that /local.sock is meant to be a Unix socket and it creates a regular file.

-- AhmetB - Google
Source: StackOverflow