How to Configure Web Server on the Top of Docker Container??
Tags: apache, docker, python, webserver
Published: 2021-03-25 06:28:11

After Reading this full article, You will be able to configure Web-Server on The top of Docker Container.

#Prerequisites:
Docker Must be installed
Basic Knowledge of how to launch docker container.

So Without any further delay, Let’s get started.

Here For performing this task I am using REDHAT 8 as the BaseOS.

Step-1: Start The Docker Service in Redhat 8 Operating System.

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpn7rusoe1c6ow22ir2f.png)
Step-2: Pull the Docker Image

To launch any isolated container we must have an image downloaded on our local system. Here I am pulling CentOS image from docker hub.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ki47l5p1nyrc8p8osuh0.png)
Step-3: Launch the container on the top of Redhat 8

Here the Command to launch a container with name as webserver can be seen below.  
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8bzx0vnnm348dk0sskgj.png)
Step-4: Install Apache Httpd software.

Here Before installing make sure to stop firewall in Base OS. In Redhat 8 to stop firewall we use systemctl stop firewalld command.

To install httpd software, run yum install httpd -y command inside the docker container.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgzwmnitokhxm47t38p9.png)
Step-5: Start The HTTPD service

Normally in Redhat 8, to start this service we always use systemctl start httpd command.But in docker we don’t have that command hence instead we use the command which is mentioned in the image below.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3xo6fwr3fuodrfr0tcn.png)

Step-6: Navigate to /var/www/html.

In this directory we have to put the webpages created by us. Here I have created one webpage called index.html.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5828in11v0ca1ji2bfsk.png)
The HTML code of this file looks like this. In this way you can also but various webpages in this folder.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5cxes9519iofgsf0fv9v.png)

Step-7: Install The net-tools software.
This software provides the command to see IP of container. 
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vte1z6dblspp4hfk3z14.png)

Step-8: Access the webpage in Browser.
Now we can access the webpage in browser as below. Syntax is IP/filename.html  
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjrb6i77bhukez30o8q6.png)

#VOILA!!! We have done it.

#BONUS:

We saw how to configure webserver on the top of docker container. Now we can also Setup Python interpreter and hence run python code on the top of docker container.

We can install python3 on docker container using yum command.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qljimc5cvfk1ujltj0p7.png)
Thats all!! Python 3 is installed in Docker Container, Now you can create a python file and simply run it.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzr5f9xk49ysietb4aew.png)
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oe93jznnux37vc6k0rtr.png)
The Final Outcome looks like below.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvwucabwbpninuexdd4s.png)
That’s ALL for NOW !!!

Thank You So Much For Reading :)