Docker aws 日志代理的图像创建 - 错误

Docker Image creation for aws log agent - ERROR

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

我的Docker文件

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

请帮我解决这个问题。

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

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

可以参考this question

您只是缺少 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'
------------------------------------------------------