Configuring Apache Webserver & Setting up Python Interpreter in Docker
Apache HTTPD is an HTTP server daemon produced by the Apache Foundation. It is a piece of software that listens for network requests (which are expressed using the Hypertext Transfer Protocol) and responds to them. It is open source and many entities use it to host their websites.
For configuring apache web-server on top of docker container running on the base Redhat OS first before launching the docker container we need to configure firewall rules.
After configuring the firewall rules, it is mandatory to restart the docker. Now we need to launch CentOS container on top of Redhat docker host. To launch a centos container using the command : docker run -it centos:7
Steps to configure APACHE WEB SERVER
- Install the httpd software using yum or dnf command.
- Create webpages. Configure the server to tell it about the webpages.
- Start your service.
Now, installing the httpd web server software using the command :
yum install httpd -y
Now we have to set-up our web-pages in /var/www/html folder, but the issue is docker doesn’t provide us with GUI, so we need vim if we want to write something in our web-page. Let’s install vim also using yum command:
yum install vim-enhanced
If we want to host our website, we have to move our webpages to this particular location (/var/www/html), only then our web server can show this webpages to the clients. We will create a test file in this directory.
The third step is to start the service, but systemctl command is not supported in docker.
As we know to any command there is a software and to that software there is program file where we can find the internal what happens when we write systemctl command and /usr/sbin/httpd is the internal file which is starting the execution.
So simply run, /usr/bin/httpd/
We can use the netstat -tnlp command to check all the running ports and hence verifying if the httpd service is running or not.
To access any web page we need the IP. In linux we can find IP by using the ifconfig command. Again the software is not installed. So, first we need to install the software and use the command .
Setting up Python Interpreter and running Python Code on Docker Container
We can simple launch python interpreter on docker container using the command:
docker run -it — name pythonInterpretor centos:7
OR
We can also install the python interpreter using the command:
yum install python3
Now we can easily use python on top of the docker using the command:
python3
After running this command, we notice that a docker container of version 7 is launched on top of our base OS. The next step is to create a file which contains the python code, but for creating the file we need either a graphical or command line based text editor, example — vim or gedit. But docker doesn’t come with these software pre-installed in it. So let’s install the software first using yum command. Head over to the base OS in another tab.
which vim Output: /usr/bin/vim
After then, let query rpm to find out the software which provides us vim — CLI text editor.
rpm -q -f /use/bin/vim
Output:
vim-enhanced-8.0.1763–13.el8.x86_64
So we can see that the software which provide vim is “vim-enhanced”. To install it in the container, go back to the container and run the following command:
yum install vim-enhanced -y
Now it’s the time to create a file with python code (let say code.py):
vim code.py
to insert the code press i
x = 9
print(x)
print(“python in docker container”)
to save the code and exit vim press :wq
Let’s run the python code:
python code.py
Output:
9
python in docker container