envy_intelligence
envy_intelligence

Reputation: 463

Uploading docker logs from ec2 instance to S3 before shutdown

Currently using an auto scaling group (ASG) on AWS, and sometimes a docker container running in an EC2 instance exits due to some ambiguous reason and the instance may get removed from the ASG. This makes debugging the failure difficult since the ASG terminates the instance and therefore erasing all the evidence of what went wrong. So, is there a way to write docker logs to S3 before it exits.

Upvotes: 1

Views: 514

Answers (1)

Kannaiyan
Kannaiyan

Reputation: 13055

You can send the logs to cloudwatch and export to s3 if needed.

Below is the process,

Add your credentials to,

/etc/init/docker.override

With,

env AWS_ACCESS_KEY_ID=
env AWS_SECRET_ACCESS_KEY=

and restart your docker service.

docker run -it --log-driver="awslogs" --log-opt awslogs-region="us-east-1" --log-opt awslogs-group="log-group" --log-opt awslogs-stream="log-stream" ubuntu:14.04 bash

This way docker sends all logs to cloudwatch.

Hope it help[s.

Upvotes: 1

Related Questions