I am trying to deploy a container on a Compute Engine VM (using the create-with-container
parameter).
The container runs a single long running task and exits. How can I shut down the VM when the container exits?
[Edit: the workload is implemented in Java and is memory intensive, hence the choice of Compute Engine rather than a managed service like App Engine or Cloud Functions]
I would create a simple web server, for example written in Python and Flask, that runs on startup inside the instance.
Create a shared secret key that the Flask web server and the container know to provide security.
Your software inside the container calls the endpoint. The endpoint calls halt(). The VM then shuts down. This would be a total of maybe 20 lines of code.
The key is that the Flask web server will need to run with privilege to call halt().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With