Configuring HTTPD Server and Python Interpreter inside Docker Container

What is Docker?

Docker is a software platform for building applications based on containers — small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another.

Docker is an open source project that makes it easy to create containers and container-based apps. Originally built for Linux, Docker now runs on Windows and MacOS as well. To understand how Docker works, let’s take a look at some of the components you would use to create Docker-containerized applications.

What we are going to do?

🔅Configuring HTTPD Server on Docker Container

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


>> systemctl start docker
We can see currently that we have pulled ubuntu and CentOS Images from the DockerHub

2. Launch a CentOS Docker Container with any name. -it means to open the terminal and it should have an interface.

docker run -it --name <name_of_container> os:version

3. Check if httpd is already installed using

>> rpm -q httpd                          (Not installed in our case)
To install httpd:
>> yum install httpd

4. After installing httpd, change to directory /var/www/html. Apache Web Server always looks for Web Files in this directory only. So, we have to keep all the code files in this directory only.

Create a page index.html in this directory. This page will be served by the Apache Web Server on the Browser. You need to have a browser in your PC.

>> cd /var/www/html
>> vi index.html

5. Create any web page. This is written in HTML Language. You can have all the code files here.

6. Now finally, you have to start the Web Server using

>> systemctl start httpd           (This will not work in container)
Web Page not showing

7. Find your IP Address using ifconfig. If it is not already installed, install it using

>> yum install net-tools

8. Now, since httpd server behind runs a program /usr/sbin/httpd.

Type this to start the Web Server Services

>> /usr/sbin/httpd

9. Type IP_Address/<file_name> to see the web page in the Browser.

10. To run a Python Code inside a Docker Container, you need to have python installed.

Install it using

>> yum install python38

11. Type python3 to open the Python Interpreter.

Now, you can write any code in Python inside a Docker Container.

12. Get out of the Docker Container by

>> exit()

Practical Completed!!

Hope you liked it!!

Thank you!!

Data Science, Big Data, Cloud Computing