无法在 AWS Batch 作业的 Docker 构建中的 Ubuntu18.04 上启动 CloudWatchAgent
我正在尝试构建一个用于 AWS Batch 作业中的 EC2 实例的映像。我需要使用 Ubuntu 18.04,因为目标是运行一些只能在 Ubuntu 18.04 上编译的 Fortran 软件。我的 Fortran 软件和一些 python 脚本在手动启动的 Ubuntu 18.04 EC2 实例上运行良好。
现在,我正在尝试使用 Docker 构建一个映像(我最终将应用到 100 个或 1000 个 EC2 实例)...但我必须安装并启动 CloudWatchAgent (CWA),但我无法获取 CWA在 Docker 构建中启动。 CWA 在我的手动 EC2 开发实例 (Ubuntu 18.04) 中启动并运行良好。我最初在手动实例中遇到了 CWA 问题,因为 CWA 使用 systemctl,所以我必须手动安装 systemd,并且在重新启动后可以正常工作。但是,我无法在 Docker 构建中复制此内容,但总是收到错误:
System has not been booted with systemd as init system (PID 1). Can't operate.
unknown init system
The command '/bin/sh -c sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:amazon-cloudwatch-agent.json' returned a non-zero code: 1
我尝试从应该已安装 systemd 的 ubuntu 18.04 映像开始,并尝试重新启动我的 EC2 实例,出现同样的错误。这是来源: https://hub.docker.com/r/jrei/systemd- ubuntu
我寻找其他想法,例如:Docker 系统尚未使用 systemd 作为 init 系统启动< /a>
...但无法弄清楚如何使其在 Docker 构建中工作。
那么,
- 我在构建中使用 Ubuntu 18.04 映像(具有 systemd)是否错误 - 如何在 Docker 构建中使用?
- 有没有另一种方法可以在 Ubuntu 18.04 中启动 CloudWatchAgent 来解决 systemd 问题?
- 它会工作/有没有办法在 Docker 构建阶段重新启动 Docker 容器内的操作系统?
- 我是否陷入困境,必须尝试在不同的 Ubuntu 或 AMI(例如 Amazon Linux)上重新编译所有内容?
还是我还缺少其他东西?
这是我的 Docker 文件:
#version with systemd already installed
FROM jrei/systemd-ubuntu@sha256:1b65424e0ec4f6772576b55c49e1470ba506504d1033e9da5795785b1d6a4d88 as ubuntu-base
RUN apt-get update && apt-get install -y \
sudo \
wget \
python3-pip
RUN sudo apt-get -y install libgfortran3
RUN sudo pip3 install boto3
RUN wget https://s3.us-east-2.amazonaws.com/amazoncloudwatch-agent-us-east-2/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
RUN sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
COPY . .
RUN cp amazon-cloudwatch-agent.json /opt/aws/amazon-cloudwatch-agent/etc/
ENV ECS_AVAILABLE_LOGGING_DRIVERS = awslogs
RUN sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:amazon-cloudwatch-agent.json
RUN mkdir -p cpseqlogs
CMD python3 cpsequence.py
感谢您的任何建议、想法或提示(我对 Docker 相当陌生,但在 Linux 上并不是完全绿色)。
I'm trying build an image for use on EC2 instances in an AWS Batch job. I need to use Ubuntu 18.04 because the goal is to run some Fortran software that I can only get to compile on Ubuntu 18.04. I have the Fortran software and some python scripts running well on a manually started Ubuntu 18.04 EC2 instance.
Now, I'm trying to build an image with Docker (that I'll eventually apply to 100s or 1000s of EC2 instances)... but I have to get CloudWatchAgent (CWA) installed and started, and I can't get CWA to start in the Docker build. CWA starts and runs fine in my manual EC2 development instance (Ubuntu 18.04). I initially had problems with CWA in my manual instance because CWA uses systemctl, and so I had to manually install systemd, and that worked after a reboot. But, I'm not able to replicate this in my Docker build, but always get the error:
System has not been booted with systemd as init system (PID 1). Can't operate.
unknown init system
The command '/bin/sh -c sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:amazon-cloudwatch-agent.json' returned a non-zero code: 1
I tried starting with an ubuntu 18.04 image that is supposed to have systemd already installed, and tried rebooting my EC2 instance, same error. Here's the source: https://hub.docker.com/r/jrei/systemd-ubuntu
I looked for other ideas, e.g.: Docker System has not been booted with systemd as init system
... but couldn't figure out how to make it work in a Docker build.
So,
- am I using the Ubuntu 18.04 image (that has systemd) in my build wrong- how to use in a Docker build?
- is there another way to start CloudWatchAgent in Ubuntu 18.04 that gets around the systemd problem?
- would it work/is there a way to restart the operating system inside the Docker container, during the docker build stage?
- am I stuck and will have to try recompile everything on a different Ubuntu or AMI like Amazon Linux?
Or is there something else I'm missing?
Here's my Docker file:
#version with systemd already installed
FROM jrei/systemd-ubuntu@sha256:1b65424e0ec4f6772576b55c49e1470ba506504d1033e9da5795785b1d6a4d88 as ubuntu-base
RUN apt-get update && apt-get install -y \
sudo \
wget \
python3-pip
RUN sudo apt-get -y install libgfortran3
RUN sudo pip3 install boto3
RUN wget https://s3.us-east-2.amazonaws.com/amazoncloudwatch-agent-us-east-2/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
RUN sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
COPY . .
RUN cp amazon-cloudwatch-agent.json /opt/aws/amazon-cloudwatch-agent/etc/
ENV ECS_AVAILABLE_LOGGING_DRIVERS = awslogs
RUN sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:amazon-cloudwatch-agent.json
RUN mkdir -p cpseqlogs
CMD python3 cpsequence.py
Thanks for any suggestions, ideas, or tips (I'm fairly new to Docker, but not totally green on linux).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论