Forward all your logs to CloudWatch Logs, like a breeze.
The simplest way to forward all your container's log to Cloudwatch is to run this repository as a container, with:
docker run -v /var/run/docker.sock:/var/run/docker.sock dberesford/docker-cloudwatchlogs -a ACCESSKEY -s SECRET_KEY -r REGION -g GROUP_NAME -t STREAM_NAME
Some environments(such as Google Compute Engine) does not allow to access the docker socket without special privileges. You will get EACCES(Error: read EACCES
) error if you try to run the container.
To run the container in such environments add --privileged to the docker run
command.
Example:
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock dberesford/docker-cloudwatchlogs -a ACCESSKEY -s SECRET_KEY -r REGION -g GROUP_NAME -t STREAM_NAME
npm install docker-cloudwatchlogs -g
docker-cloudwatchlogs -a ACCESSKEY -s SECRET_KEY -r REGION -g GROUP_NAME -t STREAM_NAME
- ..there is no step 3
Install it with: npm install docker-cloudwatchlogs --save
Then, in your JS file:
var cloudwatchlogs = require('docker-cloudwatchlogs')({
'accessKeyId': 'ACCESS_KEY',
'secretAccessKey': 'SECRET_KEY',
'region': 'REGION',
'logGroupName': 'GROUP_NAME',
'logStreamName': 'STREAM_NAME',
'bulkIndex': BULK_INDEX,
'timeout': TIMEOUT
})
// cloudwatch is the source stream with all the
// log lines
setTimeout(function() {
cloudwatchlogs.destroy()
}, 5000)
First clone this repository, then:
docker build -t cloudwatchlogs .
docker run -v /var/run/docker.sock:/var/run/docker.sock cloudwatchlogs -a ACCESSKEY -s SECRET_KEY -r REGION -g GROUP_NAME -t STREAM_NAME
This module wraps four Docker APIs:
POST /containers/{id}/attach
, to fetch the logsGET /containers/{id}/stats
, to fetch the stats of the containerGET /containers/json
, to detect the containers that are running when this module startsGET /events
, to detect new containers that will start after the module has started
This module wraps:
- docker-loghose
- docker-stats to fetch the logs and the stats as a never ending stream of data
- cloudwatchlogs-stream to stream the logs to CloudWatch
All the originating requests are wrapped in never-ending-stream.
MIT