Using Docker for build and test pipelines you can benefit from:

Image by https://foxutech.com/author/motoskia/
Let’s create a Docker container that will be used as a build agent for the Yolo5Build and Yolo5Deploy pipelines.
Take a look on the following Dockerfile:
FROM amazonlinux:2 as installer
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
RUN yum update -y \
&& yum install -y unzip \
&& unzip awscliv2.zip \
&& ./aws/install --bin-dir /aws-cli-bin/
# this is an example demostrating how to install a tool on a some Docker image, then copy its artifacts to another image
RUN mkdir /snyk && cd /snyk \
&& curl https://static.snyk.io/cli/v1.666.0/snyk-linux -o snyk \
&& chmod +x ./snyk
FROM jenkins/agent
COPY --from=docker /usr/local/bin/docker /usr/local/bin/
COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/
COPY --from=installer /aws-cli-bin/ /usr/local/bin/
COPY --from=installer /snyk/ /usr/local/bin/
This dockerfile uses Multi-stage builds. Familiarize yourself with this technique.
The dockerfile starts with amazonlinux:2 as an installer image in which we will install aws cli and snyk. After this image is built, we will copy the relevant artifacts to the other main image: jenkins/agent.
The jenkins/agent is a base image suitable for running Jenkins activities.
In addition, we copy the docker client only (as we want to build images as part of our pipeline) from docekr, which is a Docker image containing docker. Feel confused? read more….
agent any by (read more on Jenkins agent directive):
agent {
docker {
image '<image-url>'
args '--user root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
The -v mount the socket file that the docker client is using to talk with the docker daemon. In this case the docker client within the container will talk with the docker daemon on Jenkins machine.
The --user root runs the container as root user, which is necessary to access /var/run/docker.sock.
Jenkins EC2-plugin allows Jenkins to start agents on EC2 on demand, and kill them as they get unused. It’ll start instances using the EC2 API and automatically connect them as Jenkins agents. When the load goes down, excess EC2 instances will be terminated.
Amazon EC2 Jenkins plugin.none. Instead, you should check Use EC2 instance profile to obtain credentials give appropriate permissions to Jenkins` server Role (full permissions JSON can be found in the plugin’s page).Amazon Linux in the region you are operating from.*.micro type.ec2-user and AMI Type in unix.10 minutes.3 to restrict Jenkins from provisioning too many instances.off since we trust Jenkins agents by default.label property in the agent{ docker {} } setting, as follows:
agent {
docker {
label '<my-node-label>'
image '...'
args '...'
}
}