Replace the Apache Default Web Page With Sample HTML File Inside Container — Docker Assignment 5

Visal Tyagi
DevOps-Guides
Published in
5 min readApr 27, 2024

--

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

Create a Docker File Which Installs Apache2 Automatically After Running the Container — Docker Assignment 4

HTML Page
HTML Page

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”.

Search EC2
Search EC2

Step 2: Click on “Launch Instance”.

Launch instance
Launch instance

Step 3: Choose “Name” as “Assignment 5” in the “Name and tags” section.

Assignment 5 Instance
Assignment 5 Instance

Step 4: Choose “AMI” as “Ubuntu”.

Ubuntu AMI
Ubuntu AMI

Step 5: Choose “Instance type” as “t2.micro” & key pair(login) as “Docker”.

Instance type & keypair
Instance type & keypair

Step 6: Choose “Common security groups” as “launch-wizard-9”.

Choose Security Group
Choose Security Group

Step 7: Click on “Launch Instance”.

Launch Instance
Launch Instance

Step 8: Click on “hyperlink (i-041c3e5b59ce92d00)”.

Click Hyperlink
Click Hyperlink

Step 9: The instance will be in the “Running State”. Select the Instance & click on “Connect”.

Connect Instance
Connect Instance

Step 10: Again, click on “Connect”.

Connect Again
Connect Again

Step 11: Update the machine using this command:

sudo apt-get update
Update the machine
Update the machine

Step 12: Install the docker using this command:

sudo apt-get install docker.io -y
Install Docker
Install Docker

Step 13: Login as a root user to access “Docker” using this command:

sudo su -
Root Access
Root Access

Step 14: Check the “Docker” status using this command:

systemctl status docker
Docker Status
Docker Status

Docker is in an “Active” state.

Step 15: Now, we will create an index.html file using the command:

sudo nano index.html
Create index.html file
Create index.html file

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>
HTML File
HTML File

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
Dockerfile
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/
Updated Dockefile
Updated Dockefile

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 .
Build the Image
Build the Image

Step 3: The Docker Image will be successfully created as “assignment5”.

Assignment 5 Image
Assignment 5 Image

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
Container Created
Container Created

Step 5: Run this command to check whether the container is created or not:

docker container ls -a
Container Created
Container Created

Step 6: Go inside the container using the command:

docker container exec –it testcont1 bash
Inside Container
Inside Container

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
Index.html
Index.html

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
Index file content
Index file content

Step 9: Now, go to “Instances” & Click on “open address” from the “Public IPV4 Address” section.

Open Address
Open Address

Step 10: Put :89 after the IP Address 13.233.195.209. Your “index.html” file content will be opened.

HTML Page
HTML Page

Read this Docker Guide Also:

Containerized an HTML Website using Docker on Production Environment — Docker Case Study

--

--