Configuring HTTPD Server on Docker Container and Running Python Code on Docker Container
Nilesh Mathur
Senior DevOps Engineer @ Rlabs Enterprise Services Ltd.|| Certified Mentor @ Expertrons || Gen AI Enthusiast || Ex-Calance || Ex- LTTS
Our requirement here are:-
1-Configuring HTTPD Server on Docker Container
2-Setting up Python Interpreter and running Python code on Docker Container
What are the components we need??
Components required for this task are:-
1-Apache HTTPD Server:-The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.
2-Docker:-Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.
3-Python:-Python is an interpreted, high-level and general-purpose programming language.
How to host a webpage on Docker container using HTTPD Server??
1-Firstly,we need to install the Docker Container Engine in our VM.For this,we need to create a repo for docker.
Go to the folder, /etc/yum.repos.d/
Now,create a file/repo named "docker.repo" in this folder.
Now,start the docker services.
2-Now,run the command "docker ps" to check how many containers are running
This shows no container is running.
3-Now,for running a container,we need and image like centos,ubuntu etc. ,so,we will pull Docker Image from Docker Hub using command "docker pull image_name:image_version"
We can see the images using "docker images" command
4-Now,we can launch the docker container using command "docker run -it --name nameof_container image_name"
We can see that container is launched.
5-Now,we will install Apache HTTPD in this container
We can see that httpd is installed in the container.
6-Now,we can create a simple webpage in the /var/www/html folder.
7-Now,if we want to see this webpage from the browser,we need the IP Address of this container.
For,that command is ifconfig but the software that provides ifconfig ie. net-tools is not installed in the container by default.So,we need to install net-tools software.
Now,we can use ifconfig command to view IP Address.
8-Now,we will use this IP Address to see the created webpage.
Also,we need to start the services of httpd.
9-Now,we can type https://IP_Address/Nameof_webpage in the browser.
How to run the setup Python and run the Python code on Docker Container???
1-Firstly,let's install python on docker container.
2-Now.let's create a simple Python Program which will run the command of Docker container.
3-Let's run this program........................