Flexible container dispenser with single container - use awslogs log driver

I am launching one Docker container on Elastic Beanstalk using the Docking Station Single Container Configuration and trying to send the stdout application to the CloudWatch application using the awslogs log driver .

EB is looking for the Dockerrun.aws.json file to configure the container, but as far as I can see, it is not possible to use awslogs as a container registration driver (or add any other flags in docker run ).

I tried to hack the docker run using the provided here by adding the .ebextensions/01-commands.config file with content:

 commands: add_awslogs: command: 'sudo sed -i "s/docker run -d/docker run --log-driver=awslogs --log-opt awslogs-region=eu-west-2 --log-opt awslogs-group=dockerContainerLogs -d/" /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh' 

This works in the sense that it changes the mileage of the script, and the logs are displayed in CloudWatch.

But the EB application is dying. The container rises, but does not respond to requests.

I found the following error in container logs:

Team

"logs" is only supported for logging the "json-file" and "journald" drivers (received: awslogs)

I find answers to similar questions regarding ECS ​​(not EB) by suggesting adding ECS_AVAILABLE_LOGGING_DRIVERS with awslogs. But I did not find this configuration setting in EB.

Any thoughts?

+6
source share
2 answers

I post here the answer I received from AWS support:

As a single container environment with an elastic bean chest will keep the standard version and stderr on / var / log / eb-docker / container / eb-current-app / by default, and since the new decision stack allows you to stream log to cloudwatch, automating the AWSLogs agent configuration with examples, what I recommend to do is add ebextension to add the stdout and stderr log files to the cloudwatch configuration and use the already configured agent to stream these files to the cloud observation logs. instead of touching the preliminary hooks, which is equally supported by AWS, since interceptors can change from the version of the solution stack to another.

Regarding the error, you see that the "logs" command is supported only for the "json-file" and "journald" (got: awslogs) journal drivers "this error is related to the way the docker works when it is configured to send logs to another driver nearby with json-file or journald it will not be able to locally display the logs since they do not have a local copy.

 ### BEGIN .ebextensions/logs.config option_settings: - namespace: aws:elasticbeanstalk:cloudwatch:logs option_name: StreamLogs value: true - namespace: aws:elasticbeanstalk:cloudwatch:logs option_name: DeleteOnTerminate value: false - namespace: aws:elasticbeanstalk:cloudwatch:logs option_name: RetentionInDays value: 7 files: "/etc/awslogs/config/stdout.conf": mode: "000755" owner: root group: root content: | [docker-stdout] log_group_name=/aws/elasticbeanstalk/environment_name/docker-stdout log_stream_name={instance_id} file=/var/log/eb-docker/containers/eb-current-app/*-stdouterr.log commands: "00_restart_awslogs": command: service awslogs restart ### END .ebextensions/logs.config 
+8
source

I was able to extend the previous answer for a multi-level elastic beanstalk structure, as well as enter the name of the medium. I had to provide the correct permission in the ec2 role to create the log group. You can see if it works by looking at:

 /var/log/awslogs.log 

this happens in .ebextensions / logs.config

 option_settings: - namespace: aws:elasticbeanstalk:cloudwatch:logs option_name: StreamLogs value: true - namespace: aws:elasticbeanstalk:cloudwatch:logs option_name: DeleteOnTerminate value: false - namespace: aws:elasticbeanstalk:cloudwatch:logs option_name: RetentionInDays value: 14 files: "/etc/awslogs/config/stdout.conf": mode: "000755" owner: root group: root content: | [/var/log/containers/docker-stdout] log_group_name=/aws/elasticbeanstalk/`{ "Ref" : "AWSEBEnvironmentName" }`/docker-stdout.log log_stream_name={instance_id} file=/var/log/containers/*-stdouterr.log commands: "00_restart_awslogs": command: service awslogs restart 
+1
source

Source: https://habr.com/ru/post/1014618/