Task 7.2: Docker Task

Manav Misra
5 min readApr 3, 2021

A. Configuring HTTPD Server on Docker Container

B. Setting up Python Interpreter and running Python Code on Docker Container

Lets start doing this task.

For starting both the task please make sure you have docker installed.

(If not then first go and install docker)

You can confirm that you have docker installed using this command:

docker --version

Now, we are good to go to launch a container, for launching it we need an Image. I’m using centos image

Command to check the image is there or not:

docker images | grep centos

If you don’t have the image you can pull it from docker hub, command to pull the image is:

docker pull centos:latest

Now, we can list the running container, but for now we haven’t run any container so it will so the empty list

docker ps

Now we will start doing the task:

A. Configuring HTTPD Server on Docker Container

For completing this task we will run a container, I’m giving the name : httpd_server to the container, you can give any name, and the image which we downloaded which is centos:latest

docker run -it --name httpd_server centos:latest

After running this command it will get us to the docker container

Also, from the RHEL if we run docker ps command now, then it will show one container is running with the name httpd_server

Now the configuration will be done in three steps:

  1. Install the httpd software
  2. upload the file to the path /var/www/html
  3. start the services

We will do it one by one

For Installing the httpd software we have to run a command

yum install httpd -y

you can check and confirm whether the software is installed or not by querying using rpm command

rpm -q httpd

The first step is done!!

Now for uploading the file to the path /var/www/html, I’m directly creating a new file there with the name index.html and putting some random content.

cat > /var/www/html/index.htmlHello! Task 7.2-B: To configure httpd server on docker

Small Tip: press ctrl+d to come out from the cat terminal

We can check the content using

cat  /var/www/html/index.html

The second step is also done!!

Now for the last step to start the services we can run a command

/usr/sbin/httpd

And to confirm whether the server is started or not we can check the active port no, by default httpd server works on port 80

netstat -tnlp

Third step is also done!!

Now we have to check whether the server is running or not for that we need the IP of the container. We can use ifconfig command but its not pre installed so we can install it.

If we dont know which software provides the ifconfig command then we can run yum whatprovides command

yum whatprovides ifconfig

We can install the net-tools software now

yum install net-tools -y

now by writing the ifconfig command we can find the IP address

ifconfig

In my case my IP is 172.17.0.2

Now finally we can browse, http://172.17.0.2:80

That’s all!! :)

B. Setting up Python Interpreter and running Python Code on Docker Container

For completing this task we will run a container, I’m giving the name : py_test to the container, you can give any name, and the image which we downloaded which is centos:latest

docker run -it --name py_test centos:latest

After running this command it will get us to the docker container

Also, from the RHEL if we run docker ps command now, then it will show one container is running with the name py_test

Now, for setting up Python Interpreter, we can install the python3

yum install python3 -y

We can check and confirm whether python3 is installed or not

python3 --version

Now, for running a Python code here we will create a python file named test.py

vi test.py

we can display using cat command

now we will run the python code

python3 test.py

And its done!!

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

That’s all

I hope it might help you!

Thank-you! :)

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response