In this step, you will create a Dockerfile file that contains the steps to build and test a container image on your Cloud9 instance.
mkdir single cd single
You should now see a new directory named “single” appear in the file navigation panel on the left side of the Cloud9 IDE.
FROM public.ecr.aws/amazonlinux/amazonlinux:2 RUN yum -y update RUN amazon-linux-extras install epel -y RUN yum -y install stress-ng RUN echo $'#!/bin/bash\n\ echo "Passing the following arguments to stress-ng: $STRESS_ARGS"\n\ /usr/bin/stress-ng $STRESS_ARGS' >> /docker-entrypoint.sh RUN chmod 0744 /docker-entrypoint.sh RUN cat /docker-entrypoint.sh ENTRYPOINT ["/docker-entrypoint.sh"]
This is the recipie to build your container. It is based on the latest version of Amazon Linux 2 and installs the “stress-ng” utility, available from the EPEL repository, which is the computationally intensive task that you will be running throughput this workshop. Note how it creates a wrapper script called docker-entrypoint.sh to be executed when the container starts. Note also the environment variable, $STRESS_ARGS, that is used to pass command-line options to the stress-ng executable.
docker build -t stress-ng .
This process takes a little time and once complete the line of output should say: “Successfully tagged stress-ng:latest”
You should see your “stress-ng” image listed with the tag “latest”.
docker run -e STRESS_ARGS="--cpu 1 --cpu-method fft --timeout 30s --times" -i stress-ng
This program runs a stress test on the CPU and you should see the command run for a little over 30 seconds and report successful execution along with its CPU usage.
Note how the set of command line options controlling the test to perform are passed to the stress-ng executable via the STRESS_ARGS environment variable, which in this case is passed to the running container using the docker -e option.