2

According to Creating and configuring instances and my own testing, the Google Container Optimized OS launches the specified container on instance startup.

However, I'd like to execute my own startup script which would include running the container. Is there any way to prevent this default behaviour of automatically running the container on startup?

Specifiying a custom startup script for the instance doesn't seem to prevent the default behaviour.

かいぜん
  • 327
  • 2
  • 9
Gold
  • 143
  • 1
  • 6
  • 1
    From this documentation [limitation of Container-Optimized OS](https://cloud.google.com/container-optimized-os/docs/concepts/features-and-benefits#limitations) Container-Optimized OS is locked down, this means that it cannot be modified by startup scripts. – かいぜん Nov 10 '22 at 23:11
  • You can create a COS instance and either specify a [`cloud-init`](https://cloud.google.com/container-optimized-os/docs/how-to/create-configure-instance#using_cloud-init_with_the_cloud_config_format) or a [startup script](https://cloud.google.com/container-optimized-os/docs/how-to/create-configure-instance#running_startup_scripts). – DazWilkin Nov 11 '22 at 00:17
  • Don't use [`gcloud compute instances create-with-container`](https://cloud.google.com/sdk/gcloud/reference/compute/instances/create-with-container) just [`gcloud compute instances create`](https://cloud.google.com/sdk/gcloud/reference/compute/instances/create) using COS and `--metadata-from-file` or `--metadata=startup-script=` respectively. – DazWilkin Nov 11 '22 at 00:17
  • @DazWilkin I'm baffled that I didn't think of that, haha. Worked like charm. Thanks! If you want to copy your comment to an answer, I can select it as the solution :). Cheers again. – Gold Nov 13 '22 at 17:40
  • You're welcome! I'm pleased to hear it. We all have occasions where we get stuck on a path like this. This is why [Rubber Duck Dedbugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging) really does work and why "I went for a smoke and realized the solution" also works. – DazWilkin Nov 13 '22 at 17:53

1 Answers1

2

You can create a COS instance and either specify a cloud-init or a startup script.

Then use gcloud compute instances create (rather than gcloud compute instances create-with-container) and --metadata-from-file or --metadata=startup-script= respectively.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88