简体   繁体   English

如何在 docker 容器内运行 AWS CW 代理?

[英]How to run AWS CW Agent inside docker container?

I've been trying to run the CW Agent inside the container but failed.我一直在尝试在容器内运行 CW 代理但失败了。 error "unknown init system"错误“未知的初始化系统”

Im aware of docker logging driver but im trying to use the aws agent if possible.我知道 docker 日志驱动程序,但如果可能,我会尝试使用 aws 代理。

You can make use of Amazon ECS container agent.您可以使用 Amazon ECS 容器代理。

The Amazon ECS container agent allows container instances to connect to your cluster. Amazon ECS 容器代理允许容器实例连接到您的集群。 The Amazon ECS container agent is included in the Amazon ECS-optimized AMIs, but you can also install it on any Amazon EC2 instance that supports the Amazon ECS specification. Amazon ECS 容器代理包含在 Amazon ECS-optimized AMI 中,但您也可以将其安装在任何支持 Amazon ECS 规范的 Amazon EC2 实例上。 The Amazon ECS container agent is only supported on Amazon EC2 instances. Amazon ECS 容器代理仅在 Amazon EC2 实例上受支持。

Installing the Amazon ECS Container Agent 安装 Amazon ECS 容器代理

Make sure that the ec2 instance has the IAM role that allow access to ECS before you run the init command在运行 init 命令之前,请确保 ec2 实例具有允许访问 ECS 的 IAM 角色

You can use AWS cloud watch agent docker, Here is offical docker image amazon/cloudwatch-agent .您可以使用 AWS 云监视代理docker ,这是官方的docker镜像amazon/cloudwatch-agent

docker run -it --rm amazon/cloudwatch-agent

https://hub.docker.com/r/amazon/cloudwatch-agent https://hub.docker.com/r/amazon/cloudwatch-agent

Building Your Own CloudWatch Agent Docker Image构建您自己的 CloudWatch 代理 Docker 映像

You can build your own CloudWatch agent Docker image by referring to the Dockerfile located at https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/master/cloudwatch-agent-dockerfile/Dockerfile .您可以通过参考位于https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/master/cloudwatch-agent-dockerfile/Dockerfile的 Dockerfile 来构建自己的 CloudWatch 代理 Docker 映像。

FROM debian:latest as build

RUN apt-get update &&  \
    apt-get install -y ca-certificates curl && \
    rm -rf /var/lib/apt/lists/*

RUN curl -O https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb && \
    dpkg -i -E amazon-cloudwatch-agent.deb && \
    rm -rf /tmp/* && \
    rm -rf /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard && \
    rm -rf /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl && \
    rm -rf /opt/aws/amazon-cloudwatch-agent/bin/config-downloader

FROM scratch

COPY --from=build /tmp /tmp

COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

COPY --from=build /opt/aws/amazon-cloudwatch-agent /opt/aws/amazon-cloudwatch-agent

ENV RUN_IN_CONTAINER="True"
ENTRYPOINT ["/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"]

ContainerInsights-build-docker-image ContainerInsights-build-docker-image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM