Configuring HTTPD Server on Docker Container and Running Python Code on Docker Container

Configuring HTTPD Server on Docker Container and Running Python Code on Docker Container

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/

No alt text provided for this image

Now,create a file/repo named "docker.repo" in this folder.

No alt text provided for this image
No alt text provided for this image

Now,start the docker services.

No alt text provided for this image


2-Now,run the command "docker ps" to check how many containers are running

No alt text provided for this image

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"

No alt text provided for this image

We can see the images using "docker images" command

No alt text provided for this image

4-Now,we can launch the docker container using command "docker run -it --name nameof_container image_name"

No alt text provided for this image

We can see that container is launched.

No alt text provided for this image

5-Now,we will install Apache HTTPD in this container

No alt text provided for this image

We can see that httpd is installed in the container.

No alt text provided for this image

6-Now,we can create a simple webpage in the /var/www/html folder.

No alt text provided for this image
No alt text provided for this image

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.

No alt text provided for this image

Now,we can use ifconfig command to view IP Address.

No alt text provided for this image

8-Now,we will use this IP Address to see the created webpage.

Also,we need to start the services of httpd.

No alt text provided for this image

9-Now,we can type https://IP_Address/Nameof_webpage in the browser.

No alt text provided for this image

How to run the setup Python and run the Python code on Docker Container???

1-Firstly,let's install python on docker container.

No alt text provided for this image

2-Now.let's create a simple Python Program which will run the command of Docker container.

No alt text provided for this image

3-Let's run this program........................

No alt text provided for this image


Thank You!!!





要查看或添加评论,请登录

Nilesh Mathur的更多文章

社区洞察

其他会员也浏览了