Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off Google Compute instance after container exits [duplicate]

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]

like image 365
daphshez Avatar asked Nov 06 '22 23:11

daphshez


1 Answers

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().

like image 170
John Hanley Avatar answered Nov 15 '22 08:11

John Hanley