Docker图像创buildaws日志代理 – 错误

嗨,我想用aws日志代理服务创buildDocker镜像。 以下脚本我已经写了

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

*********************完结档案****************** ***

在build筑图像期间,我得到以下错误

 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 

请帮我解决这个问题。

你只是缺less你的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' ------------------------------------------------------ 

你有没有检查过你的系统上实际安装了一个cron守护进程?

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

你可以参考这个问题