Ref: https://learn.cantrill.io/courses/1820301/lectures/41301612 and https://learn.cantrill.io/courses/1820301/lectures/41301615


STEP1: Installing Docker Engine on EC2 Instance

  1. Start a t2.micro instance with Amazon Linux 2, then connect to it once running
  2. sudo dnf install docker - Install Docker
  3. sudo service docker start - Start the Docker service in the instance
  4. docker ps - List all running containers in the instance
  5. sudo usermod -a -G docker ec2-user - add local ec2-user to the Docker group (gives permissions to interact with Docker Engine)
  6. Logout from instance and login again
  7. sudo su - ec2-user - login to instance with ec2-user (needed if you're using EC2 session manager instead of Instance Connect or SSH)
  8. docker ps should now list all running containers without an error (but no containers will be running initially)

STEP2: Creating 'container of cats' Docker Image

# Build Docker Image
cd container
docker build -t containerofcats .
docker images --filter reference=containerofcats

# Run Container from Image
docker run -t -i -p 80:80 containerofcats
# Now connect to EC2 instance via HTTP, you will be greeted with a cats webapp :)

# Upload Container to Dockerhub (required for STEP3, can skip otherwise)
docker login --username=<YOUR_USER>
docker images
docker tag <IMAGEID> <YOUR_USER>/containerofcats
docker push <YOUR_USER>/containerofcats:latest

STEP3: Deploying 'container of cats' using ECS-Fargate

  1. Create an ECS Cluster, specify AWS Fargate as cluster mode
  2. Create a task definition
  3. Run the task definition in the created ECS Cluster