In this step, you create an AWS Virtual Private Cloud (VPC) to run your application stack on. Before you continue, make sure you have taken the time to learn the application architecture.
This example uses AWS but the AWS provider is only one example of an infrastructure you can use. You can create the environment design on whatever infrastructure you wish. For example, you could place the application on another public cloud platform such as Azure or DigitalOcean, on premises in your data center, or even in in a test environment on your laptop.
Note: If you are not deploying to AWS, or are not using the CloudFormation template used in the instructions below, make sure your Docker hosts are running a 3.16 or higher kernel. This kernel is required by Docker’s container networking feature.
To deploy on an AWS infrastructure, you first build a VPC and then apply apply the CloudFormation template prepared for you. The template describes the hosts in the example’s stack. While you could create the entire VPC and all instances via a CloudFormation template, splitting the deployment into two steps lets you use the CloudFormation template to build the stack on an existing VPCs.
The diagram below shows the VPC infrastructure required to run the CloudFormation template.
The configuration is a single VPC with a single public subnet. The VPC deployment relies on a cloudformation.json template which specifies in the
us-west-1 Region (N. California) or
us-west-2 (Oregon). The ability to create instances one of these regions is required for this particular CloudFormation template to work. If you want to use a different region, edit the template before the import step.
The VPC network address space is
192.168.0.0/16 and single 24-bit public subnet is carved out as 192.168.33.0/24. The subnet must be configured with a default route to the internet via the VPC’s internet gateway. All six EC2 instances are deployed into this public subnet.
Once the VPC is created, you deploy the EC2 instances using the CloudFormation template located in the
You’ll need to have an Amazon AWS account. This account can be personal or through a corporate instance. The account must be able to deploy EC2 instances in the
us-west-1 region (N. California).
Before starting through this procedure, make sure you have an existing EC2 key pair in the
us-west-1 region and that you have download its
.pem file. If you aren’t sure, login into AWS. Then, follow the AWS documentation to ensure you have the key pair and have downloaded the
This step shows you using the VPC wizard on Amazon. If you prefer to build the VPC manually, configure your VPC with the following values:
|VPC Network (CIDR)||192.168.0.0/16|
|Subnet network (CIDR)||192.168.33.0/24|
|Availability Zone||N. California (us-west-1a or b)|
|Subnet type||Public (with route to the internet)|
|Auto-assign public IP||Yes|
|Router||A single router with a route for local traffic and default route for traffic to the internet|
|Internet gateway||A single internet gateway used as default route for the subnet’s routing table|
To build the VPC, with the wizard.
Go to the VPC dashboard.
Choose Start VPC Wizard.
Make sure VPC with a Single Public Subnet is selected.
The browser displays the Step 2: VPC with a Single Public Subnet dialog.
Complete the dialog as follows:
Click Create VPC.
AWS works to build the VPC and then presents you with the VPC Successfully Created page.
Choose Subnets from the VPC Dashboard menu.
Choose Subnet Actions > Modify Auto-Assign Public IP.
Select Enable auto-assign Public IP and click Save.
In the next step, you configure the remaining AWS settings by using a CloudFormation template.
In this step, you use CloudFormation template to build a stack on AWS. Before you begin, make sure you have the prerequisites:
Then, do the following:
Go to the AWS console and choose CloudFormation.
Click Create Stack.
Under Choose a template click the Choose file button.
Browse to the download sample code and choose the the
swarm-microservice-demo-v1/AWS/cloudformation.json CloudFormation template.
The system pre-populates most of the Specify Details dialog from the template.
Name the stack
You can name the stack something else if you want just make sure it is meaningful.
Select your key pair from the KeyName dropdown.
publicSwarm for the Subnetid dropdown menu.
swarm-scale from the Vpcid dropdown menu.
Click Next twice to reach the Review page.
Check the values.
The Template URL,SubnetId and VpcId are always unique, so yours will not match, but otherwise you should see the following:
AWS displays the progress of your stack being created
When completed, the CloudFormation populates your VPC with six EC2 instances.
|Instance||Size||Private IP Address|
Navigate to the EC2 dashboard to view them running.
The underlying AWS infrastructure has this configuration.
All instances are based on the
ami-56f59e36 AMI. This is an Ubuntu 14.04 image with a 3.13 kernel and 1.10.2 version of the Docker Engine installed. Each Engine daemon was pre-configured via the
/etc/default/docker file using the following
--cluster-store=consul://192.168.33.11:8500 --cluster-advertise=eth0:2375 -H=tcp://0.0.0.0:2375 -H=unix:///var/run/docker.sock
At this point your infrastructure stack is created successfully. You are ready to progress to the next step and build the Swarm cluster.
© 2013–2016 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein.