Google Cloud Compute Instance doesn't work as expected with startup script

54 views
Skip to first unread message

I-On Project Integration

unread,
Jun 22, 2020, 11:15:04 AM6/22/20
to Google Cloud SQL discuss
I've created an Google Cloud Compute Engine Instance Template where I specify a docker container image to be used (hosted privately on Google Container Registry).
For my app I need to have Google Cloud Sql Proxy running, so I followed these steps and added a startup script on my Compute Engine Instance Template like this:

    #! /bin/bash
    wget https
://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O /var/lib/google/cloud_sql_proxy
    chmod
777 /var/lib/google/cloud_sql_proxy
    sudo
/var/lib/google/cloud_sql_proxy -instances={instance name} &

The issue I have is that when I create an Compute Engine VM Instance based on this template
   
gcloud compute instances create {instance name} --source-instance-template {template name}

The instance is created and starts and I can see that cloud_sql_proxy script is running, BUT the docker image is not pulled neither does the container starts...

I've tried to create an Compute Engine VM Instance without specifying the startup script and it works correctly, the docker image is pulled and the container starts running.
And with the Compute Instance running, I've connect via ssh and start the cloud_sql_proxy script manually and everything works (the apps connects successfully to the SQL instance on Google Cloud SQL).
But I want to have this automated...

What am I missing? Has anybody had this issue?

I-On Project Integration

unread,
Jun 22, 2020, 11:15:04 AM6/22/20
to Google Cloud SQL discuss
Google Cloud Compute Instance doesn't work as expected with startup script

Alexis (Google Cloud Support)

unread,
Jun 23, 2020, 5:31:33 PM6/23/20
to Google Cloud SQL discuss
Hello,

Let me see if I can help and if I understood properly.

I think those[1] steps you mentioned are for stateful configurations, unless you've setup volumes with your container. And I'm also not sure how how the state of the image is carried to the GCE instance. The image and script may be incompatible in some respect. The issue seems to be after you add the script to the docker image. I'm thinking that it might be better to put the SQL Proxy as part of the container, unless there's a specific reason you don't want to do that. There's an entire article here[2] that reflects exactly what you are trying to do. In that article there's a Proxy Docker image that could save you lots of trouble.

Reply all
Reply to author
Forward
0 new messages