ARTH - Task 7.2 👨🏻‍💻

ARTH - Task 7.2 👨🏻💻

Task Description📄

🌀 7.2: Docker Task

🔅Configuring HTTPD Server on Docker Container

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

This is an important article on docker and python. In this article, I have configured apache web-server on docker container and also implemented python code on the docker container by setting up python interpreter on top of it.

No alt text provided for this image


So, here we start with our first task:-

Configuring apache web-server on docker container.

I’m using RHEL 8.0 on AWS Cloud as my host os for docker and have yum configured on it.

Installation of Docker on top of our RHEL8.0.

But before this, we have to add one more Repo inside the yum configuration file of our RHEL8.0, which provides us the docker software. To download that Repo file first we have to go inside the yum configuration file directory.

Command for same is

cd /etc/yum.repos.d/

No alt text provided for this image

Now, let’s type the following code in the repo file…

[docker]
baseurl=https://download.docker.com/linux/centos/7/x86_64/stable
gpgcheck=0

Now run this command to install Docker Community Edition-

yum install docker-ce --nobest

No alt text provided for this image
No alt text provided for this image

Docker is now successfully installed. Now let’s see the version of docker.

Command used are :

rpm -aq | grep docker-ce

and command to see the version of docker is docker --version

To start the service we have :

systemctl start docker

To see the status of the service whether it is active or not we have :

systemctl status docker

No alt text provided for this image

Let’s now pull the docker image to configure the webserver on it.

No alt text provided for this image

We have a docker image in our RHEL 8.0, 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 pratik -p 8080:80 centos:latest


No alt text provided for this image


Command to see the ip address:

ip addr

NOTE:

-i:- It creates an interactive connection with Container.

-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 has IP Address 172.17.0.2 respectively.

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

No alt text provided for this image
No alt text provided for this image

HTTPD software is successfully installed.

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.

No alt text provided for this image


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

No alt text provided for this image

we have to install to net-tools because some services might not work.

command :

yum install net-tools

No alt text provided for this image

Our web-server is successfully configured.

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

From the host OS terminal, we can use the command to see it is well configured or not.

Command is:

curl http://CONTAINER_IP/FILE.HTML

No alt text provided for this image


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

Now we can set up Python Interpreter and run Python Code on Docker Container.

We already have a docker container running with us. For setting up a python interpreter we have to install the python software inside the container.

Command:-

yum install python3

No alt text provided for this image


No alt text provided for this image

Python3 is successfully installed!!!

Finally, we can run the Python3 Interpreter using:-

python3

No alt text provided for this image
No alt text provided for this image

Hence, we have successfully completed both the task.


Thanks for reading the article.

You can appreciate the article by giving it a like and posting comments about your feedback.


#arthbylw #vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #ARTH #linuxworld #makingindiafutureready #righeudcation #docker #webserver #elasticity #lvm

To view or add a comment, sign in

More articles by Pratik Kohad 🇮🇳

Others also viewed

Explore content categories