2

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).

UnclePhil
  • 23
  • 6

0 Answers0