In this tutorial we will explain you how to:
- build a node application with Docker on Local Machine
- Create an ECR repository to store our Docker Image
- Upload the Docker image to the ECR repository
- Create and launch an Elastic Container Cluster
- Launch our application as a task within the Elastic Container Cluster
- Expose and open this application on the internet
Step 1 ) Clone Below git URL for Nodeapp
git clone https://github.com/harblaith7/Docker-AWS-Crash-Course.git
Step 2) Run the following command to build an image with the tag node-web-app
docker build -t node-web-app .
Step 3) Run the following command to start the application in detached mode:
docker run -p 6565:5000 -d node-web-app
Step 4) Install and configure aws cli
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- sudo ./aws/install
- aws configure
Step 5) Create ECR Repository And Push the Docker Image
- Change --repository-name and --region
$ aws ecr create-repository --repository-name node-web-app-repo --region ap-south-1
- Tagging A Repository and Change aws_account_number, Repository Name.
$ docker tag node-web-app aws_account_number_here.dkr.ecr.ap-south-1.amazonaws.com/node-web-app-repo:latest
- Login Into Docker Client Registry
$ aws ecr get-login-password | docker login --username AWS --password-stdin aws_account_number_here.dkr.ecr.ap-south-1.amazonaws.com/node-web-app-repo
- Push Docker Image To ECR
$ docker push aws_account_number_here.dkr.ecr.ap-south-1.amazonaws.com/node-web-app-app:latest
Step 6) Create an ECS Cluster
Go to the ECS home page and click on the create cluster button:
Choose EC2 Linux + Networking and then click next:
Then enter the following information:
- name of the cluster: node-cluster
- EC2 instance type: t3-micro
- Number of instances: 1
Then choose:
- Default VPC
- Auto assign IP: Enabled
- Security group: default
- Choose one of the subnet
- And then next press Enter
Step 7) Create a new Task definition
A task is a set of metadata (memory, CPU, port mapping, environmental variables, etc) that describes how a container should be deployed.
- Click on new Task definition
- Choose EC2
Then next
Choose node-task for the name of the task definition.
- Enter 128 for memory size.
- Enter 1 vCPU for CPU Unit.
- Click Add Container:
Add the name of the container: node-container
Set the image URI that we have saved to add the end of the add image step
- Set the port mappings 6565:5000
Click create.
- Then go to Run Task
The task is now running:
If we click on the container instance:
We can modify the security group associated with the instance to open the port 6565
- Add 6565 to the inbound rule for the security group:
If we try now to open the url: http://public_IP_Address:6565
No comments:
Post a Comment
testing