Within a VM, I have a container with a simply Python script I'd like to run via a Cloud Function. I understand how to start/stop the VM, but I cannot figure out how to run the script via the Cloud Function. Is it possible to do this via a Cloud Function?
Here are the details:
This is the GCP Cloud Function which starts a VM, with code using the Python SDK.
from googleapiclient import discovery
service = discovery.build('compute', 'v1')
# Start the VM
# Project ID defined here
project = ''
zone = 'us-central1-a'
# name of the VM
instance = 'my-instance'
request = service.instances().start(project=project, zone=zone, instance=instance)
response = request.execute()
print("success!")
This VM my-instance
was deployed with a Docker container (see here for details).
Within the VM, I can use the docker container as I normally would, e.g. with docker run -it container-name python3 myscript.py
. (For the purpose of this question, it's exactly like running a script which prints "hello world" in python, as explained in this link)
How can I simply execute something like docker run -it my-container python3 my-script.py
?
Is it possible to set up docker run
to be executed when the instance is launched?