Dockerise simple customized website — Step by step implementation

Srinivasan Baskaran
Cloudnloud Tech Community
4 min readMar 19, 2024

Prerequisite: Need an Ubuntu machine with Docker installed.

Refer my article for installing Docker in Ubuntu machine: https://shorturl.at/6oJ7w

Let's quickly create a personalize webpage and once it was dockerised we will try adding more lights to the webpage.

Here is my quick webpage content for my index.html file:

<html>
<body>
<h1>Welcome to Hello World! </h1>
</body>
</html>

Assume you have the Ubuntu machine and Docker installed and here is the reference to my earlier medium.com article for quick or easy reference:

Login to the Ubuntu machine and create a working folder DockerFolder and move into this new folder

Create an index.html inside this new folder using the vi editor as below:

Note: Incase if vi editor not available by default in Ubuntu, try use the below commands for clean and quick install

sudo apt-get update
sudo apt-get install vim -y

It's time to create a simple Dockerfile (Please note the file and it should be of this name as best practice) for containerizing the Ubuntu base image with apache2 webserver with the customized webpage to the root folder as below:

FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y
RUN apt-get install apache2 -y
COPY ./index.html /var/www/html

Next to build this file to create an image by executing the following command

sudo docker build . -t bsrinivasancbe/apachehelloworld2024

This command will execute the configuration details in the current folder with the file named Dockerfile and an image will be created with the name “bsrinivasancbe/apachehelloworld2024

Execute the following command to list out all the docker images in the current directory

sudo docker images

Now the image needs to be executed to create the instance namely container as below:

sudo docker run -it -p 80:80 -d bsrinivasancbe/apachehelloworld2024

Also to list all the active containers in the current directory, execute the following command:

sudo docker ps

Hurray! you have created the docker container running on port 80 in an easy peasy steps!

Let say we want to verify the container in action, then we have to perform 2 more actions namely: enable the port 80 for the VM and start the Apache ser

vice by logging into the container as below:

To login to the running container execute the below docker command with <<containerid>> replaced with actual containerid that is listed from the above command

sudo docker exec -it <<containerid>> bash

To check the Apache service is running inside the container, execute following command to verify

service apache2 status

To start the Apache service execute the below command and again check with above command to see the service got started now.

service apache2 start

Once done exit from the container by executing the below command

exit

Now traverse to the browser and access the Public IP of the VM to see the web page getting accessed as below

Since our scope is done, let's do some clean up as best practices by stopping the container and removing from the VM machine from the following commands set:

sudo docker stop <<container_id>>

sudo docker rm <<container_id>>

Then we can delete the images by referring the image id as below

sudo docker rmi <<image_id>>

That’s it, Thank you for reading, Happy Dockerising!

Happy to share this article to help you to explore new updates, do follow me in medium.com, click the clap 👏 button below to show your valuable support.

--

--

Srinivasan Baskaran
Cloudnloud Tech Community

Qualified IT professional with over 20+ years of experience in rendering Technical Expertise in Microsoft, Cloud (Azure, AWS) .Net/SQL Development, DevOps, RDBM