<commit_before># How to use docker with swarm
This topic shows a very simple way to use [docker engine with in swarm mode](https://docs.docker.com/engine/swarm/) to create a swarm-managed cluster on Azure. It creates three virtual machines in Azure, one to act as the swarm manager, and two as part of the cluster of docker hosts. When you are finished, you can use swarm to see the cluster and then begin to use docker on it. 

> This topic uses docker with swarm and the Azure CLI *without* using legacy swarm features built into **docker-machine**. **docker-machine** has **--swarm** switches that enable you to use **docker-machine** to directly add nodes to a swarm, but these implement the legacy swarm service, not the newer **swarm-mode**. For an example, see the [docker-machine](https://github.com/docker/machine) documentation. However, we will be using the non-swarm related **docker-machine** commands to deploy the machines to Azure and to connect to them remotely to manage swarm-mode.

For the differences between Docker Swarm and Docker Swarm Mode, there is a great explaination [here](http://stackoverflow.com/questions/38474424/the-relation-between-docker-swarm-and-docker-swarmkit/38483429).

## Create docker hosts with Azure Virtual Machines

This topic creates four VMs, but you can use any number you want. **docker-machine** will save the SSH keys to your local machine.

**Confirm your Azure Subscription**

    azure account set <KEY>

**Build Swarm VMs**
Put your Subscription ID from above in the code before running these commands.  You may also want to change the azure location, resource group name and machine names to your liking. Several other switches are available with the [Azure driver](https://docs.docker.com/machine/drivers/azure/) to control the deployment. 

    $ docker-machine create --driver azure --azure-subscription-id <SUB ID> --azure-location westus --azure-size Standard_A1 --azure-resource-group ContainersSwarmMode --azure-open-port 8080 --azure-ssh-user sysadmin swarm-master-east

    $ docker-machine create --driver azure --azure-subscription-id <SUB ID> --azure-location westus --azure-size Standard_A1 --azure-resource-group ContainersSwarmMode --azure-ssh-user sysadmin swarm-node-1

    $ docker-machine create --driver azure --azure-subscription-id <SUB ID> --azure-location westus --azure-size Standard_A1 --azure-resource-group ContainersSwarmMode --azure-ssh-user sysadmin swarm-node-2

When you're done you should be able to use **azure vm list** to see your Azure VMs:

    $ azure vm list -g <RESOURCE GROUP NAME>

    data:    ResourceGroupName  Name               ProvisioningState  PowerState  Location  Size
    data:    -----------------  -----------------  -----------------  ----------  --------  -----------
    data:    swarmmodeeast      swarm-master-east  Succeeded          VM running  eastus    Standard_A1<commit_msg>Update deploy-docker-swarm.md<commit_after># How to use docker with swarm
This topic shows a very simple way to use [docker engine with in swarm mode](https://docs.docker.com/engine/swarm/) to create a swarm-managed cluster on Azure. It creates three virtual machines in Azure, one to act as the swarm manager, and two as part of the cluster of docker hosts. When you are finished, you can use swarm to see the cluster and then begin to use docker on it. 

> This topic uses docker with swarm and the Azure CLI *without* using legacy swarm features built into **docker-machine**. **docker-machine** has **--swarm** switches that enable you to use **docker-machine** to directly add nodes to a swarm, but these implement the legacy swarm service, not the newer **swarm-mode**. For an example, see the [docker-machine](https://github.com/docker/machine) documentation. However, we will be using the non-swarm related **docker-machine** commands to deploy the machines to Azure and to connect to them remotely to manage swarm-mode.

For the differences between Docker Swarm and Docker Swarm Mode, there is a great explaination [here](http://stackoverflow.com/questions/38474424/the-relation-between-docker-swarm-and-docker-swarmkit/38483429).

## Create docker hosts with Azure Virtual Machines

This topic creates four VMs, but you can use any number you want. **docker-machine** will save the SSH keys to your local machine.

**Confirm your Azure Subscription**

    az account list

**Build Swarm VMs**
Put your Subscription ID from above in the code before running these commands.  You may also want to change the azure location, resource group name and machine names to your liking. Several other switches are available with the [Azure driver](https://docs.docker.com/machine/drivers/azure/) to control the deployment. 

    $ docker-machine create --driver azure --azure-subscription-id <SUB ID> --azure-location westus --azure-size Standard_A1 --azure-resource-group ContainersSwarmMode --azure-open-port 8080 --azure-ssh-user sysadmin swarm-master-east

    $ docker-machine create --driver azure --azure-subscription-id <SUB ID> --azure-location westus --azure-size Standard_A1 --azure-resource-group ContainersSwarmMode --azure-ssh-user sysadmin swarm-node-1

    $ docker-machine create --driver azure --azure-subscription-id <SUB ID> --azure-location westus --azure-size Standard_A1 --azure-resource-group ContainersSwarmMode --azure-ssh-user sysadmin swarm-node-2

When you're done you should be able to use **azure vm list** to see your Azure VMs:

    $ az vm list -g <RESOURCE GROUP NAME>

    data:    ResourceGroupName  Name               ProvisioningState  PowerState  Location  Size
    data:    -----------------  -----------------  -----------------  ----------  --------  -----------
    data:    swarmmodeeast      swarm-master-east  Succeeded          VM running  eastus    Standard_A1
{'fraction_non_alphanumeric': 0.10793596143914615, 'fraction_numerical': 0.008951626786021691, 'mean_word_length': 3.3423019431988044, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5778225', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1472, 'n_words': 683}