Configuring HTTPD Server on Docker container

Karthik Avula
3 min readNov 2, 2020

Hello everyone, in this blog we will see how to configure a httpd service on the top of the docker container.

First, see all the images that are running using docker ps. In my case I dont have any containers running.

docker ps
docker ps

Now, pull any image on which you want to configure httpd service. In my case I am using centos 7. Pulling an image from docker hub is simple. You just use docker pull along with the image/container name you wish to pull with its version. This will help you to download an image from docker hub.

docker pull centos:7
docker pull os:version

After installing OS, run the same using docker run -i -t — name <Your OS name> <image name>:<version> Here -i is the option for interaction and -t is to get new terminal of our new OS so that we can install and configure our httpd server and — name is to give our OS a name.

docker run -i -t — name web_server centos:7

Now install our webserver (httpd) using yum command and proceed with the options you see there (Yes option). This will help you to install a webserver on our docker container.

yum install httpd

Configuring our webserver :

Now we will create a webpage and deploy it on our webserver. For this you need to enter into /var/www/html folder and there, you need to create a webpage. Lets do this

creating homepage.html file
code for homepage.html

After making a file on /var/www/html folder, now we need to start our webserver using systemctl start httpd. But on Docker you will face some issue saying “Operation not permitted”. For this, you need to goto /usr/sbin/httpd location where you will get an IP on which your website is running.

/usr/sbin/httpd
You will see a new IP when you opened this file. In my case my ip is 172.17.0.2

Now use this IP to see our webpage.

website configured on docker.

Now our webserver has been configured on the top of docker container.

If you want to push your container to docker hub, you can use “docker push” along with some tags. Docker push helps to upload our image(here-image with https configured) to docker hub and anybody who wants to use it they can pull and use.

Thanks for reading my blog.

This blog is a part of my journey in ARTH — The School of Technologies, guided by the World record holder Mr. Vimal Daga sir.

--

--

Karthik Avula

CS Student. Skillset : Linux, Bash Shell Scripting, Python, AWS, Hadoop, Ansible, Docker, Kuberntes, Networking and Troubleshooting, OS Concepts.