Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use awslog driver in to get the logs from the docker container?

I have a docker container running in EC2. The logs in the container are written at /var/log. How do I use the awslog driver to get these logs from the container and store it?

like image 658
akshaybetala Avatar asked Dec 05 '25 06:12

akshaybetala


1 Answers

Works fine for me.

  1. Create a IAM user in AWS console with the following policy:
   "Version" "2012-10-17" 
    "Statement" 
        "Action" 
            "logs:CreateLogStream" 
            "logs:PutLogEvents" 
            "Effect" "Allow" 
            "Resource"
  1. Add AWS credentials to docker host system, add a "aws-credentials.conf"
mkdir -p /etc/systemd/system/docker.service.d/
touch /etc/systemd/system/docker.service.d/aws-credentials.conf
  1. Insert into aws-credentials.conf
 [Service]
    Environment"AWS_ACCESS_KEY_ID=<aws_access_key_id>" 
    Environment"AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>"
  1. Reboot docker Host and create an Cloudwatch Logstream

  2. Add this to your docker-compose (v2) to start logging

    logging 
         driver "awslogs" 
         options 
            awslogs-region "eu-west-1" 
            awslogs-group "my-group" 
            awslogs-stream "my-stream"
    

Tested on Ubuntu 15.10

like image 89
opHASnoNAME Avatar answered Dec 07 '25 20:12

opHASnoNAME



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!