APPENDIX A

image

Using the Amazon EC2

Amazon Web Services (AWS) provides various services and Amazon Elastic Compute Cloud (Amazon EC2) is one of the services. Amazon EC2 may be used to create a virtual host server. Amazon EC2 provides a wide selection of instance AMIs (Amazon Machine Images) to choose from when creating a virtual server. In this Appendix we shall discuss creating and configuring Amazon EC2 instance/s for installing Docker and Docker images. Amazon EC2 instance is not a requirement to run Docker software and an alternative platform, local or remote, may be used instead.

  • Creating an Amazon EC2 Instance
  • Create a Key Pair
  • Starting an Amazon EC2 Instance
  • Connecting to an Amazon EC2 Instance
  • Finding the Public IP Address
  • Finding the Public DNS
  • Adding the default Security Group
  • Stopping an Amazon EC2 Instance
  • Changing the Instance Type

Creating an Amazon EC2 Instance

We have used Amazon EC2 instances based on Linux for deploying Docker and Docker images. Amazon EC2 is not a requirement and an alternative such as a local Linux installation may be used instead. The Linux platform is required to support 64 bit software. We have made use of two different 64 bit (required) AMIs:

  1. Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-d05e75b8 64 bit
  2. Red Hat Enterprise Linux version 7.1 (HVM), EBS General Purpose (SSD) Volume Type (ami-12663b7a) 64 bit

To create an Amazon EC2 Instance, an Amazon Web Services Account is required, which may be created at https://aws.amazon.com/getting-started/?nc2=h_l2_cc. To create an Amazon EC2 instance, navigate to https://aws.amazon.com/ec2/ and click on Sign In to the Console. Select EC2 from the listed Amazon Web Services. Click on INSTANCES image Instances to list the Amazon EC2 instances already created in the account. Click on Launch Instance to create a new Amazon EC2 instance as shown in Figure A-1.

9781484218297_FigAppA-01.jpg

Figure A-1. Launching an Amazon EC2 Instance

Select an AMI to create a virtual server from. Some of the AMIs are eligible for the Free tier. For example, select the Ubuntu AMI as shown in Figure A-2.

9781484218297_FigAppA-02.jpg

Figure A-2. Selecting an AMI

In Choose an Instance Type different types are available differing by features such as supported capacity and virtual CPUs (vCPUs). Select one of the Instance Types, for example the General Purpose image t2.micro and click on Review and Launch as shown in Figure A-3.

9781484218297_FigAppA-03.jpg

Figure A-3. Review and Launch

Click on Launch in Review Instance Launch as shown in Figure A-4.

9781484218297_FigAppA-04.jpg

Figure A-4. Launch

A dialog gets displayed to create or select an existing key pair. A key pair is required for authorization. To create a new key pair, select the “Create a new key pair” option as shown in Figure A-5.

9781484218297_FigAppA-05.jpg

Figure A-5. Selecting “Create a new key pair”

Specify a Key pair name and click on Download Key Pair as shown in Figure A-6. The Key pair gets created and downloaded. The key pair selected for an Amazon EC2 instance when creating the instance is required when connecting to the instance, as is discussed later in this Appendix.

9781484218297_FigAppA-06.jpg

Figure A-6. Download Key Pair

Alternatively, select the option “Choose an existing key pair” and click on Launch Instances as shown in Figure A-7.

9781484218297_FigAppA-07.jpg

Figure A-7. Choose an existing Key Pair

The Launch Status gets displayed. Click on the instance id to display the instance as shown in Figure A-8.

9781484218297_FigAppA-08.jpg

Figure A-8. Launch Status

The instance gets listed and is initially in the “pending” state as shown in Figure A-9.

9781484218297_FigAppA-09.jpg

Figure A-9. Amazon EC2 Instance in Pending State

When an instance has launched completely, the Instance State becomes “running” as shown in Figure A-10.

9781484218297_FigAppA-10.jpg

Figure A-10. Running Instance

Creating a Key Pair

As mentioned previously, a key pair is required to connect to a Amazon EC2 instance. A key pair may be created while creating an instance or separately. To create a key pair separately select Network & Security image Key Pairs as shown in Figure A-11.

9781484218297_FigAppA-11.jpg

Figure A-11. Network & Security image Key Pairs

The key pairs already created get listed. A key pair may be deleted by selecting the key pair and clicking on Delete. Click on Yes in the dialog as shown in Figure A-12.

9781484218297_FigAppA-12.jpg

Figure A-12. Delete Key Pair

To create a new key pair, click on Create Key Pair as shown in Figure A-13.

9781484218297_FigAppA-13.jpg

Figure A-13. Create Key Pair

Specify a Key pair name and click on Create button as shown in Figure A-14.

9781484218297_FigAppA-14.jpg

Figure A-14. Create Button

A new key pair gets created as shown in Figure A-15.

9781484218297_FigAppA-15.jpg

Figure A-15. New Key Pair

Starting an Amazon EC2 Instance

When a new Amazon EC2 instance is created and Launch is selected, the instance gets started. A stopped instance may be started by selecting the checkbox adjacent to the instance and selecting Actions image Instance State image Start as shown in Figure A-16.

9781484218297_FigAppA-16.jpg

Figure A-16. Actions image Instance State image Start

In Start Instances dialog click on Yes, Start as shown in Figure A-17.

9781484218297_FigAppA-17.jpg

Figure A-17. Starting an instance

Connecting to an Amazon EC2 Instance

An instance that has been started may be connected to from a local machine such as a local Linux instance without as much RAM and a different Linux distribution than the instance being connected to. The ssh command to use to connect to a running instance may be obtained by clicking on Connect as shown in Figure A-18.

9781484218297_FigAppA-18.jpg

Figure A-18. Connect

In the Connect To Your Instance dialog, the ssh command is displayed. The “docker.pem” is the key pair used to create an instance and also downloaded to the local instance from which the Amazon EC2 instance is to be connected. The username for an Ubuntu instance is “ubuntu” as shown in Figure A-19 and for a Red Hat instance is “ec2-user”.

9781484218297_FigAppA-19.jpg

Figure A-19. Connect To Your Instance dialog

The IP Address shown in the ssh command is the Public IP Address of the Amazon EC2 instance.

Finding the Public IP Address

The Public IP Address may also be obtained from the EC2 Console as shown in Figure A-20.

9781484218297_FigAppA-20.jpg

Figure A-20. Public IP Address

Finding the Public DNS

To connect to an Amazon EC2 instance process such as the HelloWorld application in Chapter 1 from a remote browser, the Public DNS is required. The Public DNS may also be obtained from the EC2 Management Console as shown in Figure A-21.

9781484218297_FigAppA-21.jpg

Figure A-21. Public DNS

The Public DNS may not get displayed initially. To display the Public DNS, select Services image VPC in the EC2 Management Console as shown in Figure A-22. VPC is a virtual private cloud assigned to a user.

9781484218297_FigAppA-22.jpg

Figure A-22. Services image VPC

In the VPC Dashboard, select Your VPCs as shown in Figure A-23.

9781484218297_FigAppA-23.jpg

Figure A-23. Your VPCs

Select the VPC listed as shown in Figure A-24.

9781484218297_FigAppA-24.jpg

Figure A-24. Selecting the VPC

From Actions, select Edit DNS Hostnames as shown in Figure A-25.

9781484218297_FigAppA-25.jpg

Figure A-25. Edit DNS Hostnames

In the Edit DNS Hostnames dialog, select Yes for the DNS Hostnames, and click on Save as shown in Figure A-26.

9781484218297_FigAppA-26.jpg

Figure A-26. Edit DNS Hostnames Dialog

Adding the default Security Group

To be able to connect from a remote browser, the Inbound and Outbound rules are required to be set to allow all traffic using any protocol on all ports in the range 0-65535 from any source. The “default” security group is configured by default to allow all traffic. We need to assign the “default” security group to the Amazon EC2 instance running Docker. Select the instance and select Actions image Networking image Change Security Groups as shown in Figure A-27.

9781484218297_FigAppA-27.jpg

Figure A-27. Actions image Networking image Change Security Groups

In the Change Security Groups panel, the “default” group might not be selected as shown in Figure A-28.

9781484218297_FigAppA-28.jpg

Figure A-28. The “default” group not selected

Select the checkbox for the “default” security group and click on Assign Security Groups as shown in Figure A-29.

9781484218297_FigAppA-29.jpg

Figure A-29. Assign Security Groups

The default security group gets assigned to the Amazon EC2 instance. To find the available security groups and their inbound/outbound rules, click on Network & Security image Security Groups as shown in Figure A-30.

9781484218297_FigAppA-30.jpg

Figure A-30. Network & Security image Security Groups

The “default” security group should be listed. Select the “default” group. Select the Inbound tab. The Type should be listed as “All Traffic”, the Protocol as “All”, the Port Range as All and Source as 0.0.0.0. To edit the inbound rules, click on Inbound image Edit as shown in Figure A-31.

9781484218297_FigAppA-31.jpg

Figure A-31. Inbound image Edit

The inbound rules get displayed and should be kept as the default settings as shown in Figure A-32. Click on Save.

9781484218297_FigAppA-32.jpg

Figure A-32. Edit inbound rules dialog

Similarly, select the Outbound tab. The Type should be listed as “All Traffic”, the Protocol as “All”, the Port Range as All and Destination as 0.0.0.0. Click on Edit as shown in Figure A-33.

9781484218297_FigAppA-33.jpg

Figure A-33. Outbound image Edit

The default settings for the Outbound rules get displayed and should be kept as the default as shown in Figure A-34. Click on Save.

9781484218297_FigAppA-34.jpg

Figure A-34. Edit outbound rules dialog

The security groups assigned to an instance are listed in the Security Groups column as shown in Figure A-35.

9781484218297_FigAppA-35.jpg

Figure A-35. Security Groups column

Stopping an Amazon EC2 Instance

To stop an Amazon EC2 instance select the instance and select Actions image Instance State image Stop as shown in Figure A-36.

9781484218297_FigAppA-36.jpg

Figure A-36. Actions image Instance State image Stop

Multiple instances may be selected and stopped together as shown in Figure A-37.

9781484218297_FigAppA-37.jpg

Figure A-37. Stopping Multiple Instances

In the Stop Instance dialog, click on Yes, Stop as shown in Figure A-38.

9781484218297_FigAppA-38.jpg

Figure 38. Stop Instance dialog

The instance/s get stopped.

Changing the Instance Type

To increase or decrease the capacity of an instance, it may be required to change the instance type, such as from a micro instance to a medium instance. An instance must first be stopped before changing its type and later restarted after modifying the type. To change the instance type, select the instance and select Actions image Instance Settings image Change Instance Type as shown in Figure A-39.

9781484218297_FigAppA-39.jpg

Figure 39. Actions image Instance Settings image Change Instance Type

In the Change Instance Type dialog, select the Instance Type to apply, for example, m3.medium as shown in Figure A-40.

9781484218297_FigAppA-40.jpg

Figure A-40. Change Instance Type dialog

Click on Apply as shown in Figure A-41.

9781484218297_FigAppA-41.jpg

Figure A-41. Applying a new Instance Type

The instance type gets upgraded to m3.medium as shown in Figure A-42. Keep in consideration that upgrading an instance type could make the instance not eligible for the free tier.

9781484218297_FigAppA-42.jpg

Figure A-42. Upgraded Instance Type

Summary

In Appendix A we discussed creating an Amazon EC2 instance based on an AMI, starting an instance, connecting to an instance, finding the Public IP Address, finding the Public DNS, changing the instance type and stopping an instance.

..................Content has been hidden....................

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