AWS Cloudwatch Agent in a docker container

I am trying to set up Amazon Cloudwatch Agent to my docker as a container. This is an OnPremise installation so it’s running locally, not inside AWS Kubernetes or anything of the sorts.

I’ve set up a basic dockerfile, agent.json and .aws/ folder for credentials and using docker-compose build to actually set it up, then launch it, but I am running into constant problems because Docker does not contain or run systemctl so I cannot run the service using AWS own documentation command:

/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

This will fail on an error when I try to run the container:

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

I’ve tried to run the /start-amazon-cloudwatch-agent inside /bin as well, but no luck. No documentation on this.

Basically the issue is how can I run this as a service or a process in the foreground? Anyone have any clues? Otherwise the container won’t stay up. Below is my code:


FROM amazonlinux:2.0.20190508
RUN yum -y install
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": {
        "metrics_collection_interval": 60,
        "region": "eu-west-1",
        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
        "debug": true

.aws/ folder contains config and credentials, but I never got as far for the agent to actually try and make a connection.

Source: StackOverflow