Configuring Web server & Python Interpreter on Docker

Priyanka Gavali
4 min readJan 14, 2022

DOCKER TASK:-

  • Configuring HTTPD Server on Docker Container.
  • Setting up Python Interpreter and running Python Code on Docker Container.

Let’s get started :

Here I am using rhel-8.1 Linux OS in VM.

First we need to install the docker container in our thel-8.1 OS. To install it using yum we need to first configure yum in our system and also create .repo for the docker.

✔ Go to yum configured file i.e. cd /etc/yum.repos.d/

✔ Create d.repo file here

After configuring yum with docker repo i.e. d.repo we can ask yum do we have any docker-ce to install in our system.

✔ Command used is:

yum list docker-ce

So now it is available.

✔ To install docker-ce command is:

yum install docker-ce --nobest

After successfully installed docker in our system. We have to start the service to use it.

Step-1 : Start the Docker Service

✔ Command used is:

systemctl start docker

✔ To check status command used is:

systemctl status docker

Step-2 : Pull the Docker Image

To install any isolated container we must have an docker image downloaded in our local system i.e. Base OS. Here I m pulling CentOS image from the docker hub.

✔ Command used is:

docker pull centos

Step-3 : Launch the Docker Container

✔ Command used is:

docker run -it --name webserver centos:latest

To know IP of OS launched we need ifconfig command which doesn’t work here. So we can ask yum that which software provides us ifconfig command.

✔ Command used is:

yum whatprovides ifconfig

So we need to install the net-tools software for ifconfig command.

✔ Command used is:

yum install net-tools

After we have installed net-tools we can run ifconfig command to know our IP Address.

Here my IP Address is 172.17.0.2

👩‍💻 To configure Apache HTTPD Webserver on Docker Container follow steps as stated below:

✔ Install httpd software

✔ Put the webpages in /var/www/html

✔ Start the Service

Step-4 : Install httpd software

Here before installing make sure to stop firewall in Base OS. In rhel-8.1 to stop firewall we use systemctl stop firewalld command and then restart the docker using systemctl restart docker command.

To install httpd software, run yum install httpd command inside the docker container.

Step-5 : Navigate to cd /var/www/html

In this directory we have to put the webpages created by us. Here I have created one webpage called web.html

Step-6 : Start the HTTPD Service

Normally to start the service we always use systemctl start httpd command. But in docker container by-default systemctl command doesn’t work. Here to start the service we use /usr/sbin/httpd

To check that we have successfully started the service, we can run the command netstat -tnlp if it shows port 80 then the service is started.

Step-7 : Access the webpage in Browser

Now we can access the webpage from our browser. Syntax is IP/filename.html

Here in my case my IP is 172.17.0.2 and file is web.html

Done !!

👩‍💻 Setting up Python Interpreter and running Python Code on Docker Container:

To setup Python Interpreter we have to install python3 in our system.

✔ Command used is:

yum install python3

So Python 3 is successfully installed in our Docker Container. Now we can run any python code here.

--

--