How to create slave jenkins given master jenkins? Below code snippet, taken from here creates master jenkins that runs in a container:

# Create Docker Group with GID
# Set default value of 497 if DOCKER_GID set to blank string by Docker Compose
RUN groupadd -g ${DOCKER_GID:-497} docker

# Used to control Docker and Docker Compose versions installed
# NOTE: As of February 2016, AWS Linux ECS only supports Docker 1.9.1
ARG DOCKER_ENGINE=1.10.2
ARG DOCKER_COMPOSE=1.6.2

# ......

# Install Docker Engine
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D &amp;&amp; \
    echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | tee /etc/apt/sources.list.d/docker.list &amp;&amp; \
    apt-get update -y &amp;&amp; \
    apt-get purge lxc-docker* -y &amp;&amp; \
    apt-get install docker-engine=${DOCKER_ENGINE:-1.10.2}-0~trusty -y &amp;&amp; \
    usermod -aG docker jenkins &amp;&amp; \
    usermod -aG users jenkins




Above container is dind that launches task(each container) on single EC2 host.



To regulate load across multiple EC2 host and launch slave jenkins instance(on each).

We would like to have master jenkins generate build_id for each build that can run on two slave jenkins instances.

To have master &amp; slave jenkins run within each container, across EC2 hosts.

How to approach on making slave container and take build_id from master jenkins?
You could use the EC2 plugin or the ECS plugin if you want to provision agents dynamically. These would provide some environment variables to use when constructing build_id - e.g. :


BUILD_TAG: 


  String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.

NODE_NAME:


  Name of the agent if the build is on an agent, or "master" if run on master



You would have to configure the clouds in Jenkins, assign a label to the templates you want to use as agents, and then request those in your pipeline or job configuration.