This is the way to build a production environment on AWS by turning a Ruby on Rails application created as a portfolio into a Docker container. The portfolio itself is here. [[Portfolio] Overview of the portfolio created during job change activities (Tec camp)] (https://qiita.com/sho_U/items/058e590325ee6833abb0)
I was suffering a lot, so I hope it helps someone.
|1||Docker containerization of Rails application in local environment|
|2||[Create a VPC on AWS. Create a public subnet]|
|3||Create a private subnet|
|4||Create an EC2 instance|
|5||Create an RDS|
|6||Upload Docker container to AWS|
It is called Virtual Private Cloud and is a virtual network created in AWS.
First, create a VPC and subbet with the following configuration.
A ** subnet ** is a further segmented network within your VPC. The app itself on the ** public subnet **. Place the database on a ** private subnet **. The public subnet is set to ** allow access from the outside **. Private subnets do not allow ** external access, only public subnets **. (The database does not need to be accessed from the outside, so to improve security)
In addition, there is no setting itself of "public subnet" and "private subnet", and the above network access restrictions will be set in the security group that will be set later.
Since the cider notation of the private IP address of vpc is 16 bits, the 16 bits from the beginning, that is, 10.0 is the network part.
Both the public and private subnets have private addresses starting at 10.0., So they are in the network inside your VPC.
Also, since the cider notation of the public subnet is/24, the network part is for 24 bits, that is, up to 10.0.10. Since the cider notation of the private subnet is also 24, 24 bits, that is, up to 10.0.20. Is the network part, Public subnets and private subnets have different network spaces.
Log in to AWS, enter the VPC dashboard, and create a VPC.
Name: Any VPC name
IPv4 CIDR block: Private IP address for VPC (10.0.0.0/16 this time)
Click "Create VPC"
Enter your VPC from the AWS console into your VPC, select your subnet and create a subnet.
Select the VPC you created earlier for your VPC ID.
Availability Zone: This time ap-northease-1a
IPv4 CIDR block: 10.0.10.0/24
Click "Create Subnet"
Roughly speaking, an IGW is like a window that connects a VPC to the Internet. VPC communication with the Internet through IGW. Attaching is the work of associating the created IGW with the VPC.
From the VPC console, select "Internet Gateway" and click "Create Internet Gateway". Decide a name and create it.
Select the IGW created from the list and click "Attach" to the VPC from the action on the upper right
Select the VPC you created earlier and click "Attach Internet Gateway"
Create a routing table for the public subnet.
Of the access that came to the public subnet
Those destined for 10.0.0.0/16 will be sent to the VPC. Those destined for 10.0.10.0/24 will be sent to the public subnet (self). 0.0.0.0/0 (all destinations other than the above) will be sent to IGW.
From the VPC console, select Route Table, click Create Route Table, name it, and select the VPC you just created for your VPC.
If you select the route you created from the list and check the "Routes" tab at the bottom, You can confirm that the destination (target) of the destination "10.0.0.0/16" is VPC (local). Since the VPC to which you belong is always required for the route table, the VPC you selected earlier will be linked.
Click the Subnet Association tab, then click Edit Subnet Association.
Select a public subnet and click Save.
Select the "Routes tab" and click "Edit Route".
Select "Add Route" and then "0.0.0.0/0". Select the IGW you just created.
Click "Save Route".
You have now created a routing table associated with your public subnet.
The following is a summary of how to make it.
It's complicated because each method is different, but what we are doing is where to distribute the communication to the destination IP address.
Click a security group on your EC2 dashboard, then click Create Security Group.
Click Add Rule.
Security group name: fitO2_SG VPC: The VPC you just created Inbound: Created as shown above
You have now created a security group that opens SSH communication (port 22) and http communication (port 80) to all access sources. Later, I plan to apply this security group to the EC2 instance I create. (The security group will be explained in a little more detail later.)
Continue to next time (3) Create Private Subnet (https://qiita.com/sho_U/items/95c25df53a7e1fd20efd)