Launching Web server and the Python Interpreter on the top of Docker Container Engine

Launching Web server and the Python Interpreter on the top of Docker Container Engine

TASK DESCRIPTION:

  • Configuring HTTPD Server on Docker Container
  • Setting up Python Interpreter and running Python Code on Docker Container

What is Docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

Docker provides tools and a platform to manage the lifecycle of your containers:

  • Develop your application and its supporting components using containers.
  • The container becomes the unit for distributing and testing your application.
  • When you’re ready, deploy your application into your production environment, as a container or an orchestrated service. This works the same whether your production environment is a local data center, a cloud provider, or a hybrid of the two.

Web Server hosting over Docker Container :

Step 1: Installation of Docker :-

Configure yum for docker :

[Docker]
name= Software for Docker Installation
baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0

Now use " yum install docker-ce --no-best -y" command to install docker.

Step 2: Start Docker Services :-

No alt text provided for this image

Use " systemctl start docker " to start docker services temporary. To make services active permanently(dose'nt stop after reboot) use " systemctl enable docker ".

Step 3: Start Docker Container :-

To get any docker image use " docker pull <image_name:version> "

To see all available docker images use " docker images "

No alt text provided for this image

To start/launch any docker container use " docker run -it --name <container_name> <image_name> "

No alt text provided for this image

To see all launched and stopped containers use " docker ps -a"

No alt text provided for this image

Step 4 : Install httpd and Python3 on launched docker container :-

To install httpd use " yum install httpd " and to install Python3 use " yum install python3 "

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

Step 5 : Create Web Pages :

To create HTML webpage upload ur code in " /var/www/html/ " folder and to create a python webpage upload ur code in " /var/www/cgi-bin/ " folder.

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

Step 6 : Start httpd Services :-

Generally in RHEL8, to start any service we can use the " systemctl " command but docker container engine doesn't support this " systemctl " command. So, instead of " systemctl " we use "/usr/sbin/httpd" command.

Docker Container IP:

No alt text provided for this image

To view the webpages use following URLs:

For html webpage : https://<container_ip>/<webpage_name>. eg. https://172.17.0.2/webpage2.html

No alt text provided for this image

For Python webpage : https://<container_ip>/cgi-bin/<webpage_name> or https://<container_ip>/cgi-bin/<webpage_name>?<arguments> (if any argument is to passed). eg: https://172.17.0.2/cgi-bin/webpage.py?x=cal

No alt text provided for this image

Running Python Code over Docker Container :

Write a python script and to run that script use : " python3 <python_script_name> "

No alt text provided for this image


Thank You so Much for Reading !!!


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

社区洞察

其他会员也浏览了