Docker for AWS

Docker for AWS is an Amazon CloudFormation template created by Docker that is designed to easily launch a Docker Swarm mode cluster in AWS with Docker best practices and recommendations applied.

Amazon CloudFormation is a service offered by Amazon that allows you to define how you would like your infrastructure to look in a template file that can then be shared or brought under version control. For more information on the service, see http://aws.amazon.com/cloudformation/.

The first thing we need to do, and it's also the only thing we need to configure ahead of launching Docker for AWS, is to ensure that we have an SSH assigned to our account in the region we will be launching our cluster. To do this, log in to the AWS console at https://console.aws.amazon.com/ or your organisation's custom sign-in page if you use one. Once logged in, go to the Service menu, which can be found in the top-left of the page, and find the EC2 service.

To make sure that you are in your desired region, you can use the region switcher in the top right between your username and the support menu. Once you are in the right region, click on Key Pairs, which can be found under Network & Security in the left-hand menu. Once on the Key Pairs page, you should see a list of your current key pairs. If you have none listed or don't have access to them, you can either click on Create Key Pair or Import Key Pair and follow the onscreen prompts.

Docker for AWS can be found in the Docker Store at https://store.docker.com/editions/community/docker-ce-aws. You have two choices of Docker for AWS: stable and Edge version. The Edge version contains experimental features from upcoming versions of Docker; because of that, we are going to look at launching Docker for AWS (stable). To do that, just click on the button and you will be taken straight to CloudFormation with the Docker template already loaded.

You can view the raw template by going to https://editions-us-east-1.s3.amazonaws.com/aws/stable/Docker.tmpl, or you can visualize the template in the CloudFormation designer. As you can see from the following visualization, there is a lot going on to launch the cluster:

The beauty of this approach is that you don't have to worry about any of these complications; Docker has you covered and has taken on all of the heavy lifting.

The first step in launching the cluster has already been sorted for you; all you have to do is click on Next on the Select Template page:

Next up, we have to Specify Details about our cluster. Other than the SSH Key, we are going to be leaving everything at their default values:

  • Stack name: Docker
  • Number of Swarm managers?: 3
  • Number of Swarm worker nodes?: 5
  • Which SSH key to use?: (select your key from the list)
  • Enable daily resource cleanup?: No
  • Use Cloudwatch for container logging?: yes
  • Swarm manager instance type?: t2.micro
  • Manager ephemeral storage volume size?: 20
  • Manager ephemeral storage volume type: standard
  • Agent worker instance type?: t2.micro
  • Worker ephemeral storage volume size?: 20
  • Worker ephemeral storage volume type: standard

Once you have checked that everything is OK, click on the Next button. In the next step, we can leave everything as it is and click on the Next button to be taken to a review page. On the review page, you will find a link that gives you the estimated cost:

As you can see, the monthly estimate for my cluster is $113.46. The final thing you need to do before launching the cluster is to tick the box that says I acknowledge that AWS CloudFormation might create IAM resources and click on the Create button. As you can imagine, it takes a while to launch the cluster; you can check on the status of the launch by selecting your CloudFormation stack in the AWS console and selecting the Events tab:

After about 10 minutes, you should see the status change from CREATE_IN_PROGRESS to CREATE_COMPLETE. When you see this, click on the Outputs tab and you should see a list of URLs and links:

To log in to our Swarm cluster, click on the link next to managers to be taken to a list of EC2 instances, which are our manager nodes. Select one of the instances and then make a note of its public IP address. In a terminal, SSH to the node using docker as the username. For example, I ran the following commands to log in and get a list of all nodes:

$ ssh [email protected]
$ docker node ls
If you downloaded a SSH key from the AWS Console when you added a key you should update the command above to include the path to your download key e.g. ssh -i /path/to/private.key [email protected]

The preceding commands to log in and get a list of all nodes are shown in the following screenshot:

From here, you can treat it like any other Docker Swarm cluster. For example, we can launch and scale the cluster service by running this:

$ docker service create --name cluster --constraint "node.role == worker" -p:80:80/tcp russmckendrick/cluster
$ docker service scale cluster=6
$ docker service ls
$ docker service inspect --pretty cluster

Now thaty your service has been launched, you can view your application at the URL given as the DefaultDNSTarget. This is an Amazon Elastic load balancer that has all of our nodes sat behind it.

Once you have finished with your cluster, return to the CloudFormation page within the AWS console, select your stack, and then select Delete Stack from the Actions drop-down menu. This will remove all traces of your Docker for Amazon Web Services cluster and stop you from getting any unexpected charges.

Docker for Azure is also available; it works in a similar way to Docker for Amazon Web Services. However, it does require a little more upfront configuration. For more information on Docker for Azure, see its Docker Store page at https://store.docker.com/editions/community/docker-ce-azure.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset