Configuring the Webserver and Setting up Python Environment on Top of Docker Container

Rahul Kumar
5 min readDec 5, 2020

--

🔅Configuring HTTPD Server on Docker Container

🔅Setting up Python Interpreter and running Python Code on Docker Container

Prerequisite for this task is Configured Docker .

Configuring Docker :

I am configuring docker on top of RHEL 8:

To install docker Firstly, we need to Configure yum repository:

Step 1. Configure Docker repository :

STEP 1.

Go to “/etc/yum.repos.d/” by sing cd command :

$ cd /etc/yum.repos.d/

STEP 2.

Create a a repo file e.g. docker.repo by using any editor , Here I am using vi editor.

$ vi docker.repo

STEP 3.

Write

[docker]

baseurl= https://download.docker.com/linux/centos/7/x86_64/stable/

gpgcheck=0

To check Yum repository is configured by using command

$ yum repolist

See in above Image Docker repo is configured .

Step 2. Install Docker

Install Docker by using command

$ yum install docker-ce --nobest

Step3.

To start Docker by using command:

$ systemctl start docker

To check Docker started or not by command:

$ systemctl status docker

TASK :-

1 .Configuring HTTPD Server on Docker Container:

To configure HTTPD Webserver on Docker We need a docker container , I am using Centos container to configure Httpd webserver.

Step 1. To launch Docker container

First , We have to download Container Image by using command

$ docker pull image_name:version (centos:latest)

now Install Docker Container by using command :

$ docker run -it --name Container_name image_name:version

Step 2. To Install Httpd server on Container:

By using command :

$ yum install httpd -y

Step 3. To Start Httpd service :

In Redhat 8 linux For starting any service we use “systemctl start service_name” command but in docker “systemctl” command does not work . so we are using command “/usr/sbin/httpd” for starting web server .

To check Httpd webserver is running or not, Use command

$ netstat -tnlp

See in the above image Port no 80 is running .

Step4. Deploy a webpage To DocomentRoot folder :

By default in webserver “/var/www/html” is DocomentRoot directory for uploading webpage . so we need to go to this folder and upload our webpage.

$ cd /var/www/html

if you have any webpage files then copy here, In my case I don’t have so I am creating a html file by vi command :-

$ vi web.html

Inside web.html file I wrote some code .

Step5. Accessing the web page by webclient(like google chrome,mozilla firefox) :

we need ip address of SYSTEM to access the webpage which we uploaded on webserver.

if we running “ifconfig” on centos 8 tghen it gives an error “command not found” so we need to configure “ifconfig” command .

To configure ifconfig command we need to install the package/tools which provides “ifconfig” command.

For finding the package/tools which provides ifconfig command,

$ yum whatprovides ifconfig

by using this command we can see “net-tools” provide ifconfig ,so we have to install net-tools for running ifconfig:

$ yum install net-tools

After Installing “net-tools” ,

see, “ifconfig” command is working.

now , to see your webpage you can run “htttp://ip_of_system/file_name” in your browser .

in my case ,by running this link http://172.17.0.2/web.html , see output :

2. Setting up Python Environment on Top of Docker Container :

For this , I am using same container where we configured webserver ,

Run “python3” to check python Environment is there or not , In my case , There is no python3 as command . see

Step1 .

To check which package provides python3 :

By Using command :

$ yum whatprovides python3

see in above image python36 provides python3 so we need to install python36 .

Step 2 .

To install python by using command

$ yum install python36

now your Python Environment set up is done .check by using “python3” command

See , In above Image python3 command is running .

Thanks ……

--

--