RM does not choose NMs to launch containers. It only launches the first container which is ApplicationMaster for the submitted application. RM also informs AM about the minimum and maximum resource capabilities of the cluster.
Then, it is Application Master's job to negotiate for resources. It will send a resource request to RM with a specfic number of containers on a specific node.
A ResourceRequest has the following form:
<resource-name, priority, resource-requirement, number-of-containers>
These components are described as follows:
resource-name is either hostname, rackname where the resource is desired, or * to indicate no preference.
priority is an intra-application priority for this request (not across multiple applications).This orders various ResourceRequests within a given application.
resource-requirement is the required capabilities such as the amount of memory or CPU time (currently YARN supports only memory and CPU).
number-of-containers is just a multiple of such containers. It limits the total number of containers as specified in the ResourceRequest.
Hope this helps !