Containerized an HTML Website using Docker on Production Environment — Docker Case Study
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.
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”.
Step 2: Choose “Name” as “Case Study”.
Step 3: Choose “AMI” as “Ubuntu”.
Step 4: Remain “Instance Type” as “t2.micro” & choose “Key pair (login)” as “Proceed without a key pair”.
Step 5: Click on “Edit” in “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”.
Step 7: Click on “Launch Instance”.
Step 8: Click on “Hyperlink” to view the “Instance”.
Step 9: “Instance” is in “Click Hyperlink. Select the instance & click on “Connect”.
Step 10: Click “Connect” in “EC2 Instance Connect”.
Step 11: “Ubuntu Machine” is ready to operate.
2. Update the Ubuntu Machine & Install Docker
Step 1: Run this command to update the machine:
sudo apt update
Step 2: Install Docker using this command:
sudo apt-get install docker.io –y
Step 3: Use these commands to start & enable the docker:
sudo systemctl enable docker
sudo systemctl start docker
Step 4: To check the status of the Docker, type this command:
sudo systemctl status docker
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
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
Step 2: Go inside the directory “w1” using the command:
cd w1
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
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
Step 5: Do “ls” & “project-html-website” have been successfully downloaded.
ls
Step 6: Do “cd project-html-website” to go inside this repository. You will land inside the “project-html-website”.
cd project-html-website
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
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/
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 .
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.
Step 5: Copy the IP Address & Paste it into the new browser address bar like this: http://35.154.146.28:88/
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
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
Step 3: Use this command to push the image:
sudo docker push visaltyagi12/myimg
Step 4: Login into your Docker hub account & go to the “Repository” section. All images will be shown here.
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
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