Connect to Docker Swarm on Azure Container Service (ACS)

Once you’ve created an Azure Container Service (ACS) deployment running Docker Swarm (as opposed to DC/OS) the next step is to be able to deploy to it from your dev machine, build machine, etc… The goal here is to be able to run docker run ... and get containers running on the Swarm cluster.

Ensure Master has Public IP

The first step will be ensure that your master has a public IP and an SSH port open, if you’ve already done this skip ahead to “Connect with Swarm”. You’ll need to ensure the machine has both a public IP attached, as well as a network security group attached.

To add a public IP:

  1. Find the master VM in your resource list
  2. Go to Settings
  3. Select Network Interfaces
  4. If the first entry has both public and private IPs listed, skip ahead to the network security group portion.
  5. Select the first entry, and go to Settings > IP Addresses
  6. Enable the public IP address and save.

To add the network security group:

  1. Follow steps 1-3 of adding a public IP above to get to Network Interfaces
  2. Select Settings > Network security group
  3. If there isn’t a group listed select Edit and then select an existing group. (If one doesn’t exist already you’ll have to create one in New Resource -> Network Security Group. Come back here after doing that)
  4. Select your NSG and go to Settings > Inbound Security Rules
  5. Click Add and Enter ssh for the name and 22 for the Destination Port Number.
  6. Save.

Wait for the operation to complete and you should now be able to SSH into the master machine with the username you created when you created the cluster, and the SSH key you specified.

Connect with Swarm

Once your ACS master is properly configured with a public IP and ssh is enabled we just need two simple commands to connect to it:

ssh -L 2375:localhost:2375 <azureuser>@<masterHostOrIP>
export DOCKER_HOST="tcp://localhost:2375"
docker info

Be sure to replace azureuser with your username and masterHostOrIP with the dnsname of your ACS master or the IP address of your master.

This sets up an SSH tunnel to your master, and forwards port 2375 from the master to your local machine. We then set the DOCKER_HOST environment variable to point docker to the forwarded port. If the docker info command works you should see the information for your swarm cluster printed out, containing a list of agent nodes in the cluster. You can now use regular docker commands, and even docker-compose!

, , , ,

No comments yet.

Leave a Reply

Proudly made in Canada