Replace the Apache Default Web Page With Sample HTML File Inside Container — Docker Assignment 5
You have been asked to:
● Create a sample HTML file
● Use the Dockerfile from the previous task
● Replace this sample HTML file inside the docker container with the default page
Before Checking this Assignment Solution, kindly check these assignment solutions before:
Create a Container on Ubuntu & Install Apache2 on It — Docker Assignment 1
Launch a Container Using a New Image & Start Apache 2 Sevice Here — Docker Assignment 2
Pull the Image from Docker Hub & Install Apache2 on a Separate Machine — Docker Assignment 3
Git Hub Repository Link for Copy the Commands:
A. Create a sample HTML file
First, we will create an EC2 Instance for performing this assignment. After the EC2 Instance Creation, we will create the “index.html” file.
Step 1: Go to the “Services” section & put the cursor over “EC2”. Click on “Instances”.
Step 2: Click on “Launch Instance”.
Step 3: Choose “Name” as “Assignment 5” in the “Name and tags” section.
Step 4: Choose “AMI” as “Ubuntu”.
Step 5: Choose “Instance type” as “t2.micro” & key pair(login) as “Docker”.
Step 6: Choose “Common security groups” as “launch-wizard-9”.
Step 7: Click on “Launch Instance”.
Step 8: Click on “hyperlink (i-041c3e5b59ce92d00)”.
Step 9: The instance will be in the “Running State”. Select the Instance & click on “Connect”.
Step 10: Again, click on “Connect”.
Step 11: Update the machine using this command:
sudo apt-get update
Step 12: Install the docker using this command:
sudo apt-get install docker.io -y
Step 13: Login as a root user to access “Docker” using this command:
sudo su -
Step 14: Check the “Docker” status using this command:
systemctl status docker
Docker is in an “Active” state.
Step 15: Now, we will create an index.html file using the command:
sudo nano index.html
Step 2: Paste the dummy content in the index.html file.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Do CTRL+X & Press Y to save the file. Press “Enter” & your file will be saved.
B. Use the Dockerfile from the previous task
Step 1: Now, we will add the index.html file to the /var/www/html location. Run the command:
vim Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
ENTRYPOINT apache2ctl -D FOREGROUND
C. Replace this sample HTML file inside the docker container with the default page
Step 1: Add this command to the Dockerfile:
ADD index.html /var/www/html/
FROM ubuntu
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
ENTRYPOINT apache2ctl -D FOREGROUND
ADD index.html /var/www/html/
Do :wq! — To quit & save the file.
Step 2: Now, we will create a separate image using the docker file.
Use this command:
docker build –t assignment5 .
Step 3: The Docker Image will be successfully created as “assignment5”.
Step 4: Now, we will create a new container using the created image through this command:
docker container run –itd --name testcont1 –p 89:80 assignment5
Step 5: Run this command to check whether the container is created or not:
docker container ls -a
Step 6: Go inside the container using the command:
docker container exec –it testcont1 bash
Step 7: Run these commands:
cd /var/www/html/ — To go inside into the html folder.
Type “ls” to view the file present in the “HTML directory”.
cd /var/www/html
ls
You will notice that the “index.html” file will be present in the “html” directory.
Step 8: Run this command: “cat index.html” file. You can easily view the content of the index file.
cat index.html
Step 9: Now, go to “Instances” & Click on “open address” from the “Public IPV4 Address” section.
Step 10: Put :89 after the IP Address 13.233.195.209. Your “index.html” file content will be opened.
Read this Docker Guide Also:
Containerized an HTML Website using Docker on Production Environment — Docker Case Study