Part 6 - Deploy and Run the Container on Amazon Elastic Contaner Service

In this task we will create an ECS Task to run the container that has been pushed to ECR.

1. Let’s jump back to your AWS console and navigate to the ECS admin interface. Once there let’s verify again that our container image is in the repository. From the ECS interface under Amazon ECR select Repositories and then click on the repository that we created previously. You should see the container image that we created and pushed.

!!!tip Make a note of Repository URI and the image tag. We will use those values in a future step to identify the container image.

a

2. Now let’s create a Task Definition. Select Task definitions from the left nav and click on Create a new Task Definition. Select EC2 and click Next step.

a

3. Enter a name for the task, review the configuration options available (we’ll leave the default values as-is) and then scroll down and click on Add container.

a

4. In the Add container UI let’s enter a Container name, and in the image field we’ll use the values from our repository noted in step #1. Pay close attention to the format required here: repository-url/image:tag

!!!info In my example the value for the Image field would be: 353497669637.dkr.ecr.ca-central-1.amazonaws.com/mvcmusicstorewedf2017:latest

Let’s enter 1024 (1GB) for a Memory Limit, and for Port mappings let’s enter 8080 for the Host port and 80 for the Container port. So far your form should look like the following:

a

Let’s scroll down and enter 1024 for CPU units and enter the following value for Entry point: C:\ServiceMonitor.exe, w3svc and then click Add

a

5. You should now see your container under Container Definitions in the Task Definitions form, click on Create and you should see the Created Task Definition Successfully message.

a

6. The final step in the sequence is to run the task we just created on our ECS host. From the Task Definitions interface mark/select the Task Definition that we just created and click on the Actions button and select Run Task.

a

7. Select a launch type of EC2, enter a Task Group name and leave the rest of the defaults. Click on Run Task.

a

8. You should receive a Created tasks successfully message and now let’s refresh the ECS Cluster UI until we see that our task status is no longer PENDING and has turned to RUNNING.

a

9. So it will take a little bit for the image to be pulled onto the box. Let’s go check on the progress on our host machine.

To do that we’ll first need to modify the Security Group rules to allow us to RDP into our ECS host server. Click on the link for Container and then click on the EC2 Instance ID.

a

a

11. First select the Inbound tab, then select Edit, then select Add Rule, then select RDP from the dropdown, then enter 0.0.0.0/0 for the CIDR and finally click Save.

a

12. Let’s RDP into our ECS Host and run a docker ps command to verify that our task/container is running. To log in click the Get Password and use the key that you downloaded previously to decrypt the password and log into the machine.

a

13. Now lets run a docker inspect command on our running container and grab it’s IP address.

a

14. And using the container’s IP let’s browse the site locally.

a

15. We’ve now confirmed that our ECS task/container is running correctly on our ECS host. The final step will be to browse to the site from the Internet using port 8080 per the task port mapping we created earlier. From your laptop open a browser and using the public IP address of the ECS host recorded in step #10 append port 8080 to the IP address and browse to the site.