I want to do something that I would think is very simple/standard - but seems impossible.
First, create a compute instance with a container:
gcloud compute instances create-with-container instance_name --container-image gcr.io/my-container-path:latest
Then ssh into it:
gcloud compute ssh instance_name --container CONTAINER_NAME
The problem is that the CONTAINER_NAME is unknown. It seems there is no way to set the container name when you create the instance in a deterministic fashion. So, after you create the instance, you need to run "docker ps" on it to determine the random name before you can use the SSH functionality.
This seems like such a standard usage pattern that I must be missing something. Any pointers are appreciated.
Solved! Go to Solution.
The container name also shows in the serial log, so you can isolate the line with this once the container is up (about 40 seconds from what I can see):
gcloud compute instances get-serial-port-output instance_name | grep "Created a container with name"
You should see something like this:
[ 34.862318] konlet-startup[608]: 2021/09/27 13:19:04 Created a container with name 'klt-containertest-kanp' and ID: 4416865e6328a967a2315325ce169356f302b4f6534acf66dbbf982403c9ee5e