Summary of Docker understanding by beginners ④ ~ Until EC2 instance is started and docker is installed ~

Introduction

Now that I've finally started learning Docker, I'll summarize my understanding. However, this time it's almost not related to docker.

What i did

Only this. It looks like this when it is represented in a diagram (uselessly annoying). スクリーンショット 2020-10-23 14.01.16.png

Set up a public subnet in your VPC

First, access the VPC console

I always select the ʻus-east-2` region. There is no particular meaning. スクリーンショット 2020-10-23 14.12.47.png

Create a VPC for the time being

CIDR blocks need to be considered firmly in the development scene, but here, 10.0.0.0/24 is specified appropriately. I recommend /16 or / 24, which have good sharpness. Tenancy doesn't seem to have to worry about personal development, whether it occupies resources or not. スクリーンショット 2020-10-23 14.15.20.png

Create an IGW and attach it to your VPC

Created. スクリーンショット 2020-10-23 14.25.03.png

Then attach it to the VPC you created earlier. スクリーンショット 2020-10-23 14.27.29.png

Only this yet. スクリーンショット 2020-10-23 14.38.36.png

Create subnet

Create a subnet in the VPC you created earlier. CIDR block is set to / 28. You can now have 2 ^ (32-28) -5 = 11 IP addresses in your subnet. Also, AZ is set to ʻus-east-2a`. スクリーンショット 2020-10-23 14.44.22.png

Also, enable automatic allocation of public IPv4 addresses for subnets. スクリーンショット 2020-10-23 14.47.36.png

I'm here. スクリーンショット 2020-10-23 14.50.44.png

Create route table

Create a route table in the VPC you created earlier. スクリーンショット 2020-10-23 14.55.12.png

Associate the created route table with the subnet created earlier. スクリーンショット 2020-10-23 14.57.38.png

Set up a route to the IGW so you can connect to the Internet. スクリーンショット 2020-10-23 14.59.02.png

I went a little. スクリーンショット 2020-10-23 15.04.17.png

Install EC2 instance in the above VPC

Access the EC2 console

スクリーンショット 2020-10-23 15.16.04.png

Instance settings

For the AMI, select the free tier ʻAmazon Linux2. For the instance type, select the free frame t2.micro`.

In the advanced instance settings, select the VPC and subnet you created earlier. Also, enable the auto-assigned public IP. Other options are not set this time. スクリーンショット 2020-10-23 15.20.55.png

Storage is OK with the default EBS settings. スクリーンショット 2020-10-23 15.23.28.png

Set the tag appropriately スクリーンショット 2020-10-23 15.24.10.png

Set up a security group. Allows all inbound communication between SSH and HTTP, and allows all communication outbound. スクリーンショット 2020-10-23 15.32.43.png

If you don't have a key pair, make a new one. スクリーンショット 2020-10-23 15.35.53.png

I'm finally here. スクリーンショット 2020-10-23 15.37.47.png

Install docker and docker-compose on your EC2 instance

Connect to an EC2 instance from your local PC

Select the target instance on the EC2 console and press the "Connect" button to display the screen below. Basically just follow this. スクリーンショット 2020-10-23 15.41.47.png

Assuming that the key pair is saved in ~ / Downloads, you can connect with the following command.

cd ~
mv Downloads/ec2-key.pem .ssh/
cd .ssh/
chmod 400 ec2-key.pem
ssh -i "ec2-key.pem" ec2-user@<your-ec2-public-ip>

I've almost reached the goal. (No, maybe it's a start) スクリーンショット 2020-10-23 15.50.47.png

Install docker on EC2

sudo yum -y update
sudo yum install -y docker
sudo gpasswd -a $USER docker
sudo service docker start

If you log in again, you can use docker.

Install docker-compose on EC2

You also need to install docker-compose, so install it according to the Official Documents.

sudo -i
curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
exit

You can now install it. Goal for the time being. スクリーンショット 2020-10-23 16.03.47.png

Save the AMI because it's a big deal

You can save an image containing all the settings with docker installed as an AMI. With it, you don't need to install docker the next time you launch an EC2 instance. You can create an AMI by action from the instance setting screen. スクリーンショット 2020-10-23 16.02.38.png

Finally

After all it was not related to docker. It's almost an article on the basics of EC2. Thank you very much.

Recommended Posts

Summary of Docker understanding by beginners ④ ~ Until EC2 instance is started and docker is installed ~
Summary of Docker understanding by beginners ⑤ ~ Until deploying docker container on EC2 instance ~
Summary of Docker understanding by beginners ⑥ ~ Until automatic deployment of docker container to EC2 instance using CodeDeploy and CodePipeline ~
Summary of Docker understanding by beginners ② ~ docker-compose ~
Summary of Docker understanding by beginners ③ ~ Until proxying API using nginx ~
Until Docker Desktop is installed and started (Windows10)
Summary of Docker understanding by beginners ① ~ docker run -p ~
I installed Docker on EC2 and started it
Summary of frequently used commands in Rails and Docker
Recommendation of set operation by Java (and understanding of equals and hashCode)