Manivannan Thirugnanam
Manivannan Thirugnanam

Reputation: 781

Docker Image creation for aws log agent - ERROR

Hi I would like to create Docker image with aws log agent service. following script i have written

My Dockerfile

FROM ubuntu:latest

ENV AWS_REGION ap-northeast-1

RUN apt-get update && apt-get install -y curl python python-pip \
        && rm -rf /var/lib/apt/lists/*
COPY awslogs.conf ./

RUN curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
RUN chmod +x ./awslogs-agent-setup.py
RUN ./awslogs-agent-setup.py --non-interactive --region ${AWS_REGION} --configfile ./awslogs.conf


RUN apt-get purge curl -y

RUN mkdir /var/log/awslogs
WORKDIR /var/log/awslogs

CMD /bin/sh /var/awslogs/bin/awslogs-agent-launcher.sh

*********************END OF FILE *****************************

during building image i get following error

Step 1 of 5: Installing pip ...DONE

Step 2 of 5: Downloading the latest CloudWatch Logs agent bits ... DONE


Step 5 of 5: Setting up agent as a daemon ...Traceback (most recent call last):
  File "/awslogs-agent-setup.py", line 1272, in <module>
    main()
  File "/awslogs-agent-setup.py", line 1268, in main
    setup.setup_artifacts()
  File "/awslogs-agent-setup.py", line 827, in setup_artifacts
    self.setup_daemon()
  File "/awslogs-agent-setup.py", line 773, in setup_daemon
    self.setup_agent_nanny()
  File "/awslogs-agent-setup.py", line 764, in setup_agent_nanny
    self.setup_cron_jobs()
  File "/awslogs-agent-setup.py", line 734, in setup_cron_jobs
    with open (nanny_cron_path, "w") as cron_fragment:
IOError: [Errno 2] No such file or directory: '/etc/cron.d/awslogs'
The command '/bin/sh -c python /awslogs-agent-setup.py -n -r eu-west-1 -c ./awslogs.conf.dummy' returned a non-zero code: 1

Please help me to fix this.

Upvotes: 2

Views: 939

Answers (2)

Tarun Lalwani
Tarun Lalwani

Reputation: 146620

You are just missing the cron package in your dockerfile. It doesn't matter if you have installed cron on your system.

FROM ubuntu:latest

ENV AWS_REGION ap-northeast-1

RUN apt-get update && apt-get install -y curl python cron python-pip \
        && rm -rf /var/lib/apt/lists/*
COPY awslogs.conf ./

RUN curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
RUN chmod +x ./awslogs-agent-setup.py
RUN ./awslogs-agent-setup.py --non-interactive --region ${AWS_REGION} --configfile ./awslogs.conf


RUN apt-get purge curl -y

RUN mkdir /var/log/awslogs
WORKDIR /var/log/awslogs

CMD /bin/sh /var/awslogs/bin/awslogs-agent-launcher.sh

After adding cron package to dockerfile everything works fine

Step 1 of 5: Installing pip ...DONE

Step 2 of 5: Downloading the latest CloudWatch Logs agent bits ... DONE


Step 5 of 5: Setting up agent as a daemon ...DONE


------------------------------------------------------
- Configuration file successfully saved at: /var/awslogs/etc/awslogs.conf
- You can begin accessing new log events after a few moments at https://console.aws.amazon.com/cloudwatch/home?region=us-west-2#logs:
- You can use 'sudo service awslogs start|stop|status|restart' to control the daemon.
- To see diagnostic information for the CloudWatch Logs Agent, see /var/log/awslogs.log
- You can rerun interactive setup using 'sudo python ./awslogs-agent-setup.py --region us-west-2 --only-generate-config'
------------------------------------------------------

Upvotes: 5

Kush Vyas
Kush Vyas

Reputation: 6089

Have you checked that a cron daemon is actually installed on your system ?

On other hand you can you can try manually installing pip3.5 install awscli-cwlogs or apt-get update && apt-get install -y python-pip libpython-dev

You can refer to this question

Upvotes: 1

Related Questions