Docker容器中的AWS Cloudwatch代理

时间:2019-09-27 05:53:55

标签: amazon-web-services docker amazon-cloudwatch

我试图将Amazon Cloudwatch Agent作为容器设置到我的Docker。这是一个 OnPremise 安装,因此它在本地运行,而不是在AWS Kubernetes或任何类型的内部运行。

我已经设置了基本的dockerfile,agent.json和.aws /文件夹作为凭据,并使用docker-compose build进行了设置,然后启动了它,但是由于Docker并没有使我遇到不断的问题包含或运行systemctl,因此我无法使用AWS自己的文档命令运行该服务:

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s

当我尝试运行容器时,这将因错误而失败:

cloudwatch_1  | /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl: line 262: systemctl: command not found
cloudwatch_1  | unknown init system

我也尝试在/ bin内部运行/ start-amazon-cloudwatch-agent,但是没有运气。对此没有任何文档。

基本上,问题是如何将其作为服务或前台进程运行?任何人都有任何线索吗?否则,容器将无法停留。下面是我的代码:

dockerfile

FROM amazonlinux:2.0.20190508
RUN yum -y install https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
COPY agent.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
CMD /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json

agent.json

{
    "agent": {
        "metrics_collection_interval": 60,
        "region": "eu-west-1",
        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
        "debug": true
    }
}

.aws /文件夹包含配置和凭据,但我从没有让代理实际尝试建立连接。

1 个答案:

答案 0 :(得分:2)

只需使用官方图片docker pull amazon/cloudwatch-agent,它将为您处理所有事情

here

如果您坚持使用自己的,请尝试以下操作:

FROM amazonlinux:2.0.20190508
RUN yum -y install https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
COPY agent.json  /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json
ENV RUN_IN_CONTAINER=True
ENTRYPOINT ["/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"]