CNFIGURING WEB-SERVER AND PYTHON INTERPRETER ON TOP OF THE DOCKER CONTAINER.

Sarvjeet Jain
5 min readMar 14, 2021

WELCOME

Welcome you all, In this blog I’ll gonna cover “HOW WE CONFIGURE APACHE WEB-SERVER ON DOCKER CONTAINER” and “HOW WE RUN PYTHON CODE ON DOCKER CONTAINER BY SETTING UP PYTHON INTERPRETER ON TOP OF IT.

So, let’s start our first task:-

CONFIGURING APACHE WEB-SERVER ON DOCKER CONTAINER.

I’M USING RED HAT 8 OS AS MY HOST OS FOR DOCKER AND HAVE YUM CONFIGURED ON IT.

STEP-1:- First we have to install Docker on top of our Host OS. But before this we have to add one more Repo inside the yum configuration file of our Host OS ,which provide us the docker software. To download that Repo file first go inside the yum configuration file directory (/etc/yum.repos.d/) and run this command:-

wget https://download.docker.com/linux/centos/docker-ce.repo

This command will download the repo file of docker inside the particular directory of your OS.

Now run this command to install Docker Community Edition-

yum install docker-ce --nobest

This command will install the Docker CE latest version on your Host OS. Run this command for confirmation that docker is successfully installed or not:-

docker --version

STEP-2:- Our Docker is installed successfully, now we have to start the docker service. Command-

systemctl start docker

This command will show you that docker service is started. Now we can use docker.

STEP-3:- Now we have to launch the Docker Container, but for launching the container we need docker image. So first we pull the docker image from the Docker Hub by using this command:-

docker pull centos:latest

This command will Pull the docker image (Centos in my case) from the Docker Hub, by using “docker images” command you will see that the image is successfully pulled.

STEP-4:- We have docker image in our Host OS, now we can easily launch the docker container using this image. We are launching Centos Docker Container, inside this container we will have to Configure the Apache Web-server. Command to launch the container:-

docker run -it --name task7 -p 8080:80 centos:latest

# -i:- It creates the interactive connection with Conatiner.

# -t:- Creates the Terminal inside the Docker Container.

# -p:- Expose the host’s 80 port with the 8080 port of Docker Container. As we mapped the host’s 80 port with the 8080 port of the container, In order to use the Public IP of Host Machine along with 8080 Port which forwards this request to Apache Webserver running on port number 80 inside the docker container.

Now use the “docker ps” command to check whether our container is launched or not.

You can see that we entered inside the Container which have IP Address 172.17.0.2 respectively.

STEP-5:- Now we have to Configure the Apache Web-server inside this container, so first we have to install the Web Server. Command:-

yum install httpd

HTTPD software is successfully installed.

STEP-6:- As we know that, the apache web-server always reads only those web pages which are present inside the “/var/www/html” directory. So we have to upload our web page inside this particular directory:-

Our web page is created inside the web-server directory.

STEP-7:- For using the Web-Server services we have to start the service. In centos we don’t have the systemctl command to start or stop the services. So for starting the web-server service we can run this command:-

/usr/sbin/httpd

Our web-server is successfully configured and also started.

STEP-8:- Now we have to check that our web-server is working or not. We have many options to check:-

From HOST_OS TERMINAL- curl http://CONTAINER_IP/FILE.HTML

From HOST_OS BROWSER- http://CONTAINER_IP/FILE.HTML

From OUTSIDE WORLD- http://HOSTOS_IP:8080/FILE.HTML

So finally our Web-server is configured successfully and working.

Let’s start our second task:-

SETTING UP PYTHON INTERPRETER AND RUNNING PYTHON CODE ON DOCKER CONTAINER.

STEP-1:- We already have docker container running with us. For setting up python interpreter we have to install the python software inside the container. Command:-

yum install python3

Python3 is successfully installed in our container.

STEP-2:- To see whether the software is installed or not, use this command:-

python3 --version

STEP-3:- Now we can run the Python3 Interpreter using :-

python3

HURRAY FINALLY WE COMPLETED OUR BOTH TASK SUCCESSFULLY…

THANK YOU FOR READING THIS ARTICLE, HOPE IT HELPS YOU..

FOR MORE SUCH TYPE OF ARTICLES STAY CONNECTED..

--

--