Configuring HTTPD Server on Docker container

Sarthak Agarwal
4 min readMar 14, 2021

In this article I will be explaining about how to launch the httpd webserver inside the docker container in a very easy manner from your base Operating system Rhel8.

So let’s see how to do this 🌀

We have pre-installed docker image in our base operating system so we just directly start up the docker services by using the command 👉

# systemctl start docker

To check whether the docker services are running or not we use the command 👉

#systemctl status docker

You can see the above image for the better understanding.

Here we have precreated CentOS image launched by the command 👉

#docker run -it --name OS8 centos:latest

So we just directly opened that particular container.

To launch this container we need to start it first as 👉

We used the command

#docker start OS8

to start that particular container or we have another option to start that particular container by using its reference name in place of its name given by us.

Coming on to the next part, we are now entering into the docker container’s terminal,so we used the command

# docker attach OS8

We will get the terminal like this way 👆

In the next step we have to install the httpd software inside the docker container which is named as OS8.

So we used the yum command as
#yum install httpd
In my case it was pre-installed so I get very few lines of output.

Now we have to go inside the main directory of the httpd software which is /var/www/html . To go inside this directory we used cd command as

#cd /var/www/html

And then we create a file named as index.html by using the vi command as

# vi index.html

And then we insert our code there. I had put a sample line only but you can also put some php script or many more front end coding in it.

Going on again to our base operating system we have to get the IP of our docker container.So we used the command 👉

# ifconfig enp0s3

And here we checked under the name of docker0 and inet is our IP address as shown in the above image. 👆

Coming on to the launching part of the webserver

We had to simply open the firefox browser by clicking on the activities option.

Here we have given the IP of our container so that we can check our webserver is running properly or not .

Here we got the output as soon as we run the IP on the firefox browser.

Hope you will practice the same and will get your concepts clear by this approach.✍️

Thank You for giving the article a full read. 🙏

Happy Learning !!!

--

--

Sarthak Agarwal

Cloud & DevOps Enthusiast ★ARTH Learner ★ AWS ★ GCP ★ Jenkins ★ K8S ★ Ansible ★ MLOps ★ Terraform ★ Networking ★ Python