Configuring HTTPD Server on Docker Container

Milind Rastogi
3 min readApr 9, 2021

In this blog I will be configuring the httpd server on a docker container. After reading this blog you will came to know how to host a website on a docker container.

For the practical I will be using RHEL 8 as my base OS and also make sure that docker is also installed on your base OS.

So let’s get started

Step1: Launching a Docker Container

I will be using the Centos OS as my docker container

docker pull centos

Above command will download the latest version of centos os

For launching the container

docker run -it --name webserver24 centos

Step2: Installing the httpd server

I will be using the yum package manager for installing the httpd server. Other distribution of Linux have different package manager so you can use respective package managers of your base OS.

yum install httpd

Step3: Configuring the webserver

For hosting any website on httpd server we have to store all our webpages in /var/www/html folder. So here I have made a index.html file for testing our webserver.

Step4: Starting the server

For launching any server in linux we can use systemctl command but by default our container image of centos does not contain this command. So we will directly use that server command which systemctl execute.

The command name is

/usr/sbin/httpd

Now we can test our webserver , so just write the url on your base OS browser

site is now hosted

Step:5 Make the webserver command permanent

If we want the webserver to automatically start after launching the container then we have to edit the /root/.bashrc file and paste the server command

Now after launching the container webserver will start and the site can be viewed using the URL which is the IP of the docker container.

Thank you for Reading !

--

--