Daily Goals – Continue Ch. 2 AWS Compute Services; HOL Launching a Docker Container on AWS; HOL Launch an Apache Webserver on an EC2 Instance
This was the first time I had ever played with Docker containers and I was very impressed with not only the utility of containers, but their ease of use. I attempted to launch an Apache web server on an EC2 instance using four different methods. Three methods used User Data when launching the EC2 instance. The fourth method used a launch template to launch the EC2 instance. All four methods failed to display a working web page. However, I was able to successfully configure and deploy a working Nginx web server in a Docker container in about 10 minutes
Method #1 – failed
Using an Amazon Linux 2 AMI, I copy and pasted the following script into the user data section when configuring the instance:
Method #2 – failed
Using an Amazon Linux 2 AMI, I attached the user-data-metadata.sh file I created locally to the User Data section when configuring the instance. The file contained the above shell script
Method #3 – failed
Using an Ubuntu Server LTS AMI, I copy and pasted the following script into the User Data section when configuring the instance:
#!/bin/bash
apt-get update
apt-get install -y apache2
echo “Welcome to My Website” > index.html
cp index.html /var/www/html
Method #4 – success
Using an Ubuntu Server LTS AMI, I created a launch template that included the above shell script when configuring the instance.
Launching a Docker container on AWS
- Created a container (task) cluster named MyCluster
- Created a task definition for cluster named fargate-task that uses the Fargate serverless compute service and nginx web server
- Proceeded to run the task fargate-task
- Using the public IP address of the newly created container, I was able to display the default Nginx web server page