I've been using startup-script
metadata many times with GCE, but not with containers.
I'm trying to deploy a GCR image to a compute instance.
Instance created with this command:
gcloud compute instances create my-instance --image-project=cos-cloud --image-family=cos-77-lts --machine-type=e2-micro --zone=us-central1-a --metadata=GCR_ADDRESS=$GCR_ADDRESS --metadata-from-file=startup-script=./start.sh --tags=http-server,https-server
The start.sh
script contains this:
#!/bin/bash
METADATA=http://metadata.google.internal/computeMetadata/v1
SVC_ACCT=$METADATA/instance/service-accounts/default
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token | cut -d'"' -f 4)
docker login -u oauth2accesstoken -p $ACCESS_TOKEN https://gcr.io
GCR_ADDRESS=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/GCR_ADDRESS" -H "Metadata-Flavor: Google")
wget https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json
docker run -it --rm --security-opt seccomp=./seccomp.json $GCR_ADDRESS
The problem is that startup-script
doesn't get started.
I can SSH into this instance and run the start.sh
script manually. It works fine, pulls the image, starts the container etc.
Cloud Logger shows no traces of the startup-script
running.
What am I doing wrong?
journalctl
is present in COS, but if it is you can look at the boot logs from an SSH session. – John Hanleyjournalctl
but not in Cloud Logging? – stkvtflw