Configuring HTTPD Server on Docker Container

Avadhut Shinde
4 min readMar 14, 2021

Why we use docker??

Docker is a container management service. The whole idea of Docker is for developers to easily develop applications, ship them into containers which can then be deployed anywhere within few seconds.

What is the use of Apache Webserver? How it works?

📌The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.

Firstly we need to create a repo file inside folder cd /etc/yum.repos.d eg :docker.repo as you can see in below snapshot

To download docker community edition i.e a free or open source edition we use : #yum install docker-ce — nobest here it will download stable & latest docker version from internet i.e. from repo file using site https://download.docker.com/linux/centos/7/x86_64/edge/Packages/

Now to Start Services of docker we use: #systemctl start docker

To check status of services we use : #systemctl status docker

To permanently enable services of docker after each reboot we use : #systemctl enable docker

To configure WEB-SERVER on docker we need a O.S to download any O.S from hub.docker.com we use : # docker pull os:name

Here I am downloading centos : latest from https://hub.docker.com/_/centos?tab=tags here we can get command to run inside our o.s also we can manually download o.s from this site https://hub.docker.com/_/centos?tab=tags

hub.docker.com is a repository site were we can find commands and images of different O.S of docker without any charges. Also we can create our own images and upload on this site.

To pull any image from hub.docker.com firstly we need to disable firewall security using #systemctl stop firewalld also we need to change mode of SELINUX using #setenforce 0 then we need to restart docker container using #systemctl restart docker.

Now we are ready to go and download centos: latest o.s.

Then to install,run,boot and login to o.s we use command : #docker run -i -t os-name : version here -i means interactive to -t terminal/bash shell.

Now to configure(install) apache webserver(httpd) inside docker container we use : #yum install httpd.

Now to start any services we use #systemctl but by default in docker it doesn’t support systemctl so how to solve this challenge??

Here we have a another way or trick to start web-server services so by using # /usr/sbin/httpd we can start services of web-server.

After that we need to check status of web-server is running or not so we need a software called as net-tools.

To install s/w of net-tools we use : #yum install net-tools

Now we can check services of web-server i.e running on port number : 80 using command : #netstat -tnlp

Hence,Challenge Solved Web-Server is successfully configured on top of docker-container✌️

We can also create web-pages inside cd /var/www/html

For example : # vi gc.html

To check web-pages created or not we can use #curl http://Docker-IP/gc.html

Now we can run this web-page inside our browser using docker_container-ip/gc.html as we can see in below snapshot

Finally, we have accomplished TASK 7.2.A i.e Configuring HTTPD Server on Docker Container ! !

Thank you !

--

--