Configuring HTTPD web-Server and Setting up Python Interpreter on the top of Docker Container
What is Docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.
In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications to be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.
Before configuring webserver and python interpreter let’s first install Docker in our system. Here I am installing Docker on my Red Hat VM.
First go inside the /etc/yum.repos.d/ directory using this command:
Now create a file docker.repo using vi docker.repo
After this create a .repo file in which write the Repo ID, baseurl, and add gpgcheck=0
Save this file and run the yum repolist command to check that your docker repo is successfully created and configured.
Now let’s install the Docker Community Edition in the system using the command:
Docker is successfully installed in your system. Now start the docker service and check the status of your docker
systemctl start docker
systemctl status docker
Configuration of Web Server
Before configuring the web server we have to pull the Docker image in our local system and start the Docker container. Here will be using Centos version 8 docker image. Command to pull the docker image and view the docker images you have in your system are:-
docker pull centos
Now we have to run the docker container using the below command.
docker run -it — name webserver centos:latest
Let’s install httpd in our container using the following command:
yum install httpd
After installing httpd go inside the /var/www/html folder and create a .html file
To start the httpd in the Docker container we need to enter the command given below because systemctl start httpd do not work in the docker container.
Setting up the Python Interpreter
Let’s run our new docker container using the command written above and install the python3 in this container using the command given below.
yum install python3
Your python interpreter is now successfully installed . For testing let’s run a small code in python using our python interpreter. I have made a file gagan.py and executed using python3 .
Congratulations , you have successfully configured HTTPD web server and the Python Interpreter in your Docker Container.