Configure Docker Swarm and an Overlay Network

You must first install Docker on each cluster node and then configure Docker Swarm
and an overlay network.

Maintain a host list file that specifies every host in the cluster and a worker
list file that specifies all the nodes except the one selected to be the Docker Swarm
master. You can use this information to run commands in parallel across the
cluster.

  1. Use the pssh command to install Docker on all the hosts in the
    cluster.

    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo yum install -y yum-utils device-mapper-persistent-data lvm2"
    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo yum install -y docker-ce"
    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo systemctl start docker"
    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo systemctl enable docker"
    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo docker run --rm hello-world"

    The following example shows the required commands:

  2. Configure Docker Swarm and create an overlay network.

    ssh -i ~/user1.pem user1@<masternode> "sudo docker swarm init"
    pssh -i -h workerlist -l user1 -x "-i ~/user1.pem" "sudo <output from last command: docker swarm join ...>"
    ssh -i ~/user1.pem user1@<masternode> "sudo docker network create -d overlay --attachable yarnnetwork"

    The following example shows the required commands:

  3. Optional:

    If Kerberos is not enabled, create a default user for containers.

    pssh -i -h hostlist -l user1 -x "-i ~/user1.pem" "sudo useradd dockeruser"

    The following example shows how you can create a default user:

Configure Docker settings for YARN using Ambari.