I'm running a container-optimized compute instance with this startup-script:
#!/bin/bash
mkdir /home/my-app
cd /home/my-app
export HOME=/home/my-app
docker-credential-gcr configure-docker
docker run --rm --log-driver=gcplogs --name my-app --security-opt seccomp=./config.json gcr.io/my-project/my-app:latest
The --log-driver
and --name
flags are set according to GCP community guide and docker docs.
Yet I see no logs from the container boot up.
Also, when I'm SSHing into the instance and running command logger "hello from logger"
, I don't see it showing up in cloud logger. I've tried converting it to advanced filters and removing all filtering except "hello from logger" string filter.
How do I properly setup the logging? I'm using bunyan
inside my NodeJS app, but when it the app fails I have absolutely no visibility? I'd love to have all the logs from journalctl
in cloud logger. Or, at least the startup-script
part of journalctl
. Right now I'm retrieving them by SSHing into the instance and running journalctl -r | grep startup-script
.
Update
Access scopes are correctly set:
Stackdriver Logging API: Write Only
Stackdriver Logging API: Write Only
I'm using a default compute engine service account. Here the command that I'm creating this VM with:
gcloud compute instance-templates create $APP_ID-template \
--scopes=bigquery,default,compute-rw,storage-rw \
--image-project=cos-cloud \
--image-family=cos-77-lts \
--machine-type=e2-medium \
--metadata-from-file=startup-script=./start.sh \
--tags=http-server,https-server
gcloud compute instance-groups managed create $APP_ID-group \
--size=1 \
--template=$APP_ID-template
Startup-script:
#!/bin/bash
mkdir /home/startDir
cd /home/startDir
export HOME=/home/startDir
docker-credential-gcr configure-docker
docker run --log-driver=gcplogs --name my-app --security-opt seccomp=./config.json gcr.io/project-id/app:latest
This VM running a NodeJS script. I'm not providing JSON keys to my NodeJS script. The bunyan
logger is correctly sending logs to the cloud logger. It only fails to send logs when server completely crashes.
Logging API is enabled. I'm getting this:
● stackdriver-logging.service - Fluentd container for Stackdriver Logging
Loaded: loaded (/usr/lib/systemd/system/stackdriver-logging.service; static; vendor preset: disabled)
Active: inactive (dead)
When running sudo systemctl status stackdriver-logging
command in a VM