用于aws日志代理的Docker镜像创建 - 错误

时间:2017-09-27 09:25:14

标签: amazon-web-services docker dockerfile ubuntu-16.04

您好我想用aws日志代理服务创建Docker镜像。 我编写的以下脚本

我的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

*********************文件结束*********************** ******

在构建图像期间,我收到以下错误

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

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:4)

您只是缺少dockerfile中的cron包。如果您在系统上安装了cron,则无关紧要。

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

将cron包添加到dockerfile后,一切正常

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'
------------------------------------------------------

答案 1 :(得分:1)

您是否检查过系统上实际安装了cron守护程序?

另一方面,您可以尝试手动安装pip3.5安装awscli-cwlogs或apt-get update&amp;&amp; apt-get install -y python -pip libpython-dev

您可以参考this question