Docker Community Forums

Share and learn in the Docker community.

Send logs to Google Logs Viewer from docker container

To do: Send logs to Google Logs Viewer from docker container.

Faced Error I followed this article: https://docs.docker.com/config/containers/logging/gcplogs/ and executed docker run --log-driver=gcplogs nginx

docker: Error response from daemon: failed to initialize logging driver: unable to connect or authenticate with Google Cloud Logging: rpc error: code = PermissionDenied desc = The caller does not have permission.

OS: Container Optimized OS cos-81-12871-1196-0

I also tried this The Google Cloud Logging driver for Docker with service account with log.admin and log.writer role

How do I send the logs to Stackdriver/Google Cloud Logging?

To use the gcplogs driver as the default logging driver, set the log-driver and log-opt keys to appropriate values in the daemon.json file, which is located in /etc/docker/ on Linux hosts or C:\ProgramData\docker\config\daemon.json on Windows Server. For more about configuring Docker using daemon.json, see daemon.json.

The following example sets the log driver to gcplogs and sets the gcp-meta-name option.

{
“log-driver”: “gcplogs”,
“log-opts”: {
“gcp-meta-name”: “example-instance-12345”
}
}
Restart Docker for the changes to take effect.

You can set the logging driver for a specific container by using the --log-driver option to docker run:

docker run --log-driver=gcplogs …
This log driver does not implement a reader so it is incompatible with docker logs.

If Docker detects that it is running in a Google Cloud Project, it discovers configuration from the instance metadata service. Otherwise, the user must specify which project to log to using the --gcp-project log option and Docker attempts to obtain credentials from the Google Application Default Credential. The --gcp-project flag takes precedence over information discovered from the metadata server so a Docker daemon running in a Google Cloud Project can be overridden to log to a different Google Cloud Project using --gcp-project.

Docker fetches the values for zone, instance name and instance ID from Google Cloud metadata server. Those values can be provided via options if metadata server is not available. They do not override the values from metadata server.