How to configure webserver and python interpreter on the top of Docker
Docker:
Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allow you to run many containers simultaneously on a given host. Containers are lightweight because they don’t need the extra load of a hypervisor, but run directly within the host machine’s kernel. This means you can run more containers on a given hardware combination than if you were using virtual machines. You can even run Docker containers within host machines that are actually virtual machines.
Webserver:
A web server is a computer that runs websites. It's a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP). These web pages are mostly static content that includes HTML documents, images, style sheets, test etc. Apart from HTTP, a web server also supports SMTP (Simple Mail transfer Protocol) and FTP (File Transfer Protocol) protocol for emailing and for file transfer and storage.
Description of task:
- Configuring HTTPD Server on Docker Container
- Setting up Python Interpreter and running Python Code on Docker Container
Solution:
step1:
To install docker in our RHEL8 OS, we have to use the given command:
yum install docker-ce --nobest
step2:
After installing docker, we need to pull the docker images by using the given command. In this task we used the centos.
docker pull centos
step3:
Now we launch the docker container by using given command:
docker run -it — name=mywebserver centos
step4:
To configure webserver, we have to install httpd package in our docker conatiner.
step5:
Now we create a file with extension .html in the /var/www/html folder by using following commands:
cd /var/www/html
vi index.html
step6:
Now we use the given command to enable the httpd service.
/usr/sbin/httpd
step7:
Now to check the ip address, we have to install the net-tools package by using given command:
yum install net-tools -y
We use the given command to check ip address.
ip addr
step8:
Now our webserver is working as we can see in the below image.
step9:
To run python code in our docker container, we have to install python package by using given command:
yum install python3
step10:
After installing python3, we can run python code as we can see in the below image.