3

I've got a container which logs normally through the standard Docker drivers. I've now run this container on GCP via the gcloud compute instances create-with-container command, and I want to see the logs in Stackdriver. Right now, they do not appear.

From what I can tell, combining the advice from here and here, I have to start the host instance, set the default logging driver to GCP by editing docker's daemon.json, and then restart the host instance.

Is this truly the easiest way to get these containers to log to the normal standard google cloud logging solution? I think that gcloud compute instances create-with-container should do this by default, and that I'm missing something.

7
  • Here's a recipe crica 2017 - cloud.google.com/community/tutorials/docker-gcplogs-driver Commented Dec 5, 2019 at 5:09
  • 1
    @Kolban - That article will not work for GCE Container OS as you can only start one container with COS. The solution is to install Stackdriver on the instance. This can be done with a startup script or manually once. Commented Dec 5, 2019 at 5:49
  • I meant one container automatically with Compute Engine. Commented Dec 5, 2019 at 6:02
  • @JohnHanley Do you know if it's possible to install stackdriver agent directly in the container? Maybe it's not the best pattern to tight the running environment with the workload process? Commented Dec 5, 2019 at 8:02
  • I don't think you can. Stackdriver runs as a service. The release notes for Container OS mention bug fixes for Stackdriver. This means that there should be a solution for your issue. Commented Dec 5, 2019 at 8:22

3 Answers 3

2

Okay, turns out the Stackdriver logger does work nicely by default when using gcloud compute instances create-with-container, so your logs should appear automatically.

They didn't for me because it seems that an f1-micro instance doesn't have the grunt to spin up a container that does even a small amount of work on top of the Docker overhead - switching to a g1-small fixed this.

Sign up to request clarification or add additional context in comments.

Comments

2

For me, the issue was about permissions. Classic.

I used the --service-account parameter to create the container with a custom service account, but it did not have the Logging Write and Monitoring Write permissions. I though using --scopes=default would be enough, but no.

FWIW, I'm using a f1-micro to run a small node.js background app (no HTTP server) and the logging works without a problem.

For whoever visits this in the future, have a look at this checklist to verify your setup.

Comments

1

Your VM runs at Compute Engine, so it doesn't contain Stackdriver logging service as it included by default only in "VMs are running in Google Kubernetes Engine or App Engine".

I completely agree with @JohnHanley. You have to install Stackdriver Logging service on your instance manually accordingly to the guideline here. At first, I'd recommend you to check supported VM list just to be sure that logging service will run at your instance properly and then follow the rest of the instructions. In case you have any troubles after installing logging services follow the troubleshooting. Please provide additional information about your steps if you won't solve the problem in this way.

UPDATE to clarify my answer. By default Stackdriver is able to collect only limited logs from the instance (list). So, in case you want to get more logs from you VM additional configuration will be required.

1 Comment

Stackdriver logging IS included on VMs running Compute engine. However, it logs the host instance logs, not the docker container logs. I believe what I need to do is update the host instance docker driver daemon.json file to use stackdriver via a startup script. Cumbersome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.