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

Visal Tyagi
DevOps-Guides
Published in
7 min readApr 29, 2024

Problem Statement:

You work as a DevOps Engineer in a leading Software Company. You have been asked to Dockerize the applications on the production server. The company uses custom software, therefore there is no pre-built container that can be used.

https://github.com/microsoft/project-html-website.git

Assume the following things:

1. Assume the software to be installed is Apache

2. Use an Ubuntu container

The company wants the following things:

1. The Developers will not be working with Docker, hence from their side, you will get the code. Write a Docker file that could put the code in the custom image that you have built.

2. Push an Image to Docker-Hub with the above config.

HTML Website (Docker Case Study)
HTML Website (Docker Case Study)

Git Hub Repository Link for Copying the Commands for this Case Study

1. Create a New Instance using the Ubuntu Machine

Step 1: First, we will launch an instance. Click on “Launch Instance”.

Launch Instance
Launch Instance

Step 2: Choose “Name” as “Case Study”.

Docker Case Study Instance
Docker Case Study Instance

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

Ubuntu AMI
Ubuntu AMI

Step 4: Remain “Instance Type” as “t2.micro” & choose “Key pair (login)” as “Proceed without a key pair”.

Instance type & Key
Instance type & Key

Step 5: Click on “Edit” in “Network Settings”.

Network Settings
Network Settings

Step 6: Choose these options here:

a. First, choose “Create Security Group” here.

b. Security group name — required: Case Study

c. Description: Security Group for Case Study

Choose “All Traffic” in the “Security group rule 2” with “Source type” as “Anywhere”.

Security Group Creation
Security Group Creation
All Traffic
All Traffic

Step 7: Click on “Launch Instance”.

Launch Instance
Launch Instance

Step 8: Click on “Hyperlink” to view the “Instance”.

Click Hyperlink
Click Hyperlink

Step 9: “Instance” is in “Click Hyperlink. Select the instance & click on “Connect”.

Instance running
Instance running

Step 10: Click “Connect” in “EC2 Instance Connect”.

EC2 Instance Connect
EC2 Instance Connect

Step 11: “Ubuntu Machine” is ready to operate.

Case Study Machine
Case Study Machine

2. Update the Ubuntu Machine & Install Docker

Step 1: Run this command to update the machine:

sudo apt update
Update the Machine
Update the Machine

Step 2: Install Docker using this command:

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

Step 3: Use these commands to start & enable the docker:

sudo systemctl enable docker
sudo systemctl start docker
Enable Docker
Enable Docker

Step 4: To check the status of the Docker, type this command:

sudo systemctl status docker
Docker Status
Docker Status

Step 5: Login as “root user” through the “sudo su –“ command. And, type “docker –version” to check the docker current version, which we are using.

sudo su -
docker --version
Docker Version
Docker Version

3. Create a New Folder & Clone the Git-Hub Repository

Step 1: We create the “w1” directory using the “mkdir w1” command & type “ls” command to check the directory here.

mkdir w1
w1 directory
w1 directory

Step 2: Go inside the directory “w1” using the command:

cd w1
Inside w1 directory
Inside w1 directory

Step 3: We have opened the “project-HTML-website” directory on “Git Hub”. Click on “Code” & Copy the Given URL from here.

https://github.com/microsoft/project-html-website.git
HTML Website Directory
HTML Website Directory

Step 4: Type this command to download this “html website” repository in the “w1” directory:

git clone https://github.com/microsoft/project-html-website.git
clone the directory
clone the directory

Step 5: Do “ls” & “project-html-website” have been successfully downloaded.

ls  
project-html-website
project-html-website

Step 6: Do “cd project-html-website” to go inside this repository. You will land inside the “project-html-website”.

cd project-html-website
Go to project-html-website directory
Go to the project-html-website directory

Problem 1 Solution: The Developers will not be working with Docker, hence from their side you will get the code. Write a Docker file that could put the code in the custom image that you have built.

Step 1: First, create the docker file using this command:

vim Dockerfile
Create a Dockerfile
Create a Dockerfile

Step 2: Put this code inside the Docker file:

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

Press “ESC” from the keyboard & type “:wq!” to quit & save the file.

Step 3: Now, create an image using this command:

sudo docker build –t myimg .
Build Docker Image
Build Docker Image

Step 4: Now, create a container using this command:

docker container run –itd -p 88:80 –name test076 myimg

Do “docker ps –a” to check whether the container is active or not.

docker ps -a

We have created the container on port 88.

Container Created
Container Created

Step 5: Copy the IP Address & Paste it into the new browser address bar like this: http://35.154.146.28:88/

HTML Website (Docker Case Study)
Website Deployed

Your website has been successfully deployed over port no. 88.

Problem 2 Solution: Push an Image to Docker-Hub with the above config.

Step 1: Tag an image to push into the Docker Hub. Use this command:

sudo docker tag myimg visaltyagi12/myimg
Tag the Image
Tag the Image

An image with the name visaltyagi12/myimg has been successfully created.

Step 2: First login into docker using this command: sudo docker login with username & password. The login will be successful.

sudo docker login
Docker Login Via CLI
Docker Login Via CLI

Step 3: Use this command to push the image:

sudo docker push visaltyagi12/myimg
Push the Image
Push the Image

Step 4: Login into your Docker hub account & go to the “Repository” section. All images will be shown here.

Docker Hub Images
Docker Hub Images

More Docker Assignments

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 that installs Apache2 Automatically After Running the Container — Docker Assignment 4

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

Check the Other DevOps Case Study Here

Integration of DevOps Tools with Jenkins — Jenkins Case Study

Creating an Architecture using Terraform on AWS — Terraform Case Study

Suggested a Git Workflow Architecture to Manage the Product Release — Git Case Study 1

Resolve Merge Conflict in The GitHub Repository — Git Case Study 2

Create Two Server Groups & Install Apache on The First Group & NGINX on the Second Group — Ansible Case Study

--

--