Configuring HTTPD Server On Docker Container

Pawan Kumar
3 min readNov 16, 2020

So when we listen about the term container technology then the very first use case that comes in our mind is running our webserver on container so that whenever loads increases on our webserver then it can launch a new container with same webserver and reduce the load on server. Through this article I gonna demonsrate configuring Apache Web Server(httpd) on docker container.

Let’s start….

Pre-requisites

  • Docker installed
  • Image of centos form docker hub downloaded

Launching Container

First we have to launch a container from any downloaded image in docker (I am using centos:latest here)

with command:- docker run -it -p 1234:80 — name os1 centos:latest

using command: Used ‘-it’ to get the intaracting terminal of container, ‘-p’ to expose the container httpd server(which works on port number 80) to outside world so that anyone can access with base OS ip and given port number

Launch Container

Installing Apache Web Server On Container

By default container don’t have apache web server installed we can check with following command: rpm -q httpd

HTTPD Package Not Installed

So to install we can use yum program as: yum install httpd -y

Installing Httpd

Now if we again check with rpm command then it will show the package installed :

HTTPD Installed

Creating web Page on Container

Now let’s create a web page on container first go to /var/www/html/ directory:

Creating web page

Here I’m just creating simple webpage for the demonstration you can create your own web page according to your all need..

Content of web page

Accessing Web Page

Now access the web page of container from outside world with base OS IP where docker is installed and with the same port as above with which we had exposed the container.

I’m writing 192.168.225.185:1234/home.html as address on browser where 192.168.225.185 is my base OS IP

Accssing web page
And the result

That’s it guys hope this article helps you…

Connect me on LinkedIn for more updates

Thank You!!!!

--

--