Skip to content

Instantly share code, notes, and snippets.

@chexxor
Created February 1, 2017 17:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chexxor/236644b168b5c05e7dbdd60c513f3f68 to your computer and use it in GitHub Desktop.
Save chexxor/236644b168b5c05e7dbdd60c513f3f68 to your computer and use it in GitHub Desktop.
cloudsql-proxy Dockerfile
FROM ubuntu
RUN apt-get update && apt-get -y install wget \
&& wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 \
&& mv cloud_sql_proxy.linux.amd64 cloud_sql_proxy \
&& chmod +x cloud_sql_proxy \
&& mkdir /cloudsql;
# Expects cred-file.json to be in working directory.
# This isn't good, but I haven't had time to improve yet.
COPY . /cloudsql
# Docs mention something about not needing cred file if running in GCE Instance, but I had issues.
# Don't forget to add SQL scope to the GCE Instances.
# Unconfirmed this is required, but I had errors when I didn't have this.
# Need to stop instances, then add scope, then restart - it's no big problem.
#CMD ["./cloud_sql_proxy", "-instances=PROJECT_ID:GCE_REGION:MYSQL_DB_NAME=tcp:0.0.0.0:3306"]
# Attempt to create cred.json on-build from env var.
#CMD ["echo \"$CRED_JSON\" > \"creds.json\" && ./cloud_sql_proxy", "-instances=PROJECT_ID:GCE_REGION:MYSQL_DB_NAME=tcp:0.0.0.0:3306", "-credential_file=/cloudsql/cred-file.json"]
CMD ["./cloud_sql_proxy", "-instances=PROJECT_ID:GCE_REGION:MYSQL_DB_NAME=tcp:0.0.0.0:3306", "-credential_file=/cloudsql/cred-file.json"]
# Listens to 3306 inside the container, but to access this, must hit port 80 from sibling Deis apps,
# as all Deis apps map port 80 to app's port.
EXPOSE 3306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment