Docking docker compose and cloudwatch

Time:2020-10-18

When using docker compose to run the service, we can view the container‘s log in the command line, but this may not be enough. We may need to store the log persistently and hope to be able to retrieve it conveniently. The cloudwatch service of AWS provides us with powerful log management capability. How can we use docker compose This paper provides a successful practice step to output the log generated by the service of cloudwatch.

Configure AWS permissions

  1. create a file/etc/systemd/system/docker.service.d/aws-credentials.conf
  2. Write the following to a file

    [Service]
    Environment="AWS_ACCESS_KEY_ID=<aws_access_key_id>"
    Environment="AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>"
  3. implementsudo systemctl daemon-reloadReload virtual machine configuration
  4. implementsudo service docker restartRestart docker
  5. implementsystemctl show --property=Environment dockerCheck that the configuration is in effect

Configure docker- compose.yml

Add logging configuration to the service that needs to collect logs (for more configuration items, please refer to the official documentation)

version: '2'
services:
  my-service:
    image: my-service:latest
    logging:
      driver: awslogs
      options:
        awslogs-region: ap-northeast-1
        awslogs-group: /log-prod/my-service

implementdocker-compose up -dRestart the docker compose container.

Check whether the docking is successful

Enter the cloudwatch menu of AWS and open the log group where the service is located. By default, we should be able to see the log stream named by the container ID, which indicates that the docking has been successfully completed.

Docking docker compose and cloudwatch

Recommended Today

Construction of Vue development environment and project creation under mac

start First of all, let’s take a look at the overall development environment of Vue. Homebrew: package manager under MAC system, similar to apt get under Linux, windows control panel – install and remove program Node.jsJavaScript runtime, which is similar to simultaneous interpretation in international conferences, can’t run various programming languages directly between different systems […]