Configuring Webserver and Python Interpreter In Docker Container.

Mohd Sabir
4 min readJan 25, 2021

--

What is Docker?

Docker is a set of platform as a service (PaaS) 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. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines.

What is HTTPD Server?

Apache HTTP Server is a free and open-source web server that delivers web content through the internet. Apache HTTP Server, also known as httpd.

What is Python?

Python is an interpreted, high-level and general-purpose programming language. Python’s design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.

Task Description :-

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

Prerequisite for this task:-

  • Docker configure in your base system

Let’s start doing our task:-

🔅Configuring HTTPD Server on Docker Container

First we have to launch our docker container than further task we will do in our docker container.

for launching the container we use command

“docker run -it — name taskos centos:latest”

here I have used centos (container image) , in centos yum already configured , let’s do next step

if we want to configure webserver in our system we have to follow three steps

  • Install the software(httpd)
  • Configure it(copy the webpages into /var/www/html folder)
  • Start the services.

for installing the apache webserver we have to use httpd software , let’s install

“yum install httpd -y”

using above command our httpd software will install properly , now we will copy our webpages into /var/www/html folder( /var/www/html is by default document root for webserver )

from our base system or docker host (“where your docker is running that system known as docker host” ) we will run this cmd to copy file

“docker cp src container_name/id :dest_path”

let’s check after going inside container that file is copied or not

it’s copied

now we will start the service of webserver, for starting the service we use command

“/usr/sbin/httpd”

but this command will start the service temporary based , as the container stop or restart the service will stop , how to start service permanently

To start the service permanently mostly we use systemctl command but in docker container systemctl command doesn’t work then how we can start service permanently in docker container , for this we have to write our command “/usr/sbin/httpd” in “.bashrc” because when the container start this file always run .

“vi /root/.bashrc”

now we will access our webpages using curl command , for accessing the webpages we need IP of our docker container , to get IP of docker container either we can use “ifconfig” command inside docker container or “docker inspect container_name” command from docker host

now we will access our webpages from docker container

curl http://ip_of_container

it’s accessing

It is accessing from docker host , let’s try to access from public world

it is not accessing

it is not accessing from public because when we launch any container in docker then they launch it in isolated environment if we want to access our webpages from public than we have expose our container to public world. for exposing we use this command

“docker run -it — name taskos -p 8080:80 centos:latest”

by default my webserver runs on port 80 , and I am exposing my webserver on port 8080, further installation we have to do as above.

Now it’s working fine.

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

for python interpreter we have to install it, let’s install it

“yum install python36 -y"

python install successfully

let’s use python interpreter

done!!

Thanks for reading!!

--

--

Mohd Sabir
Mohd Sabir

Written by Mohd Sabir

DevOps Enthusiastic || Kubernetes || GCP || Terraform || Jenkins || Scripting || Linux ,, Don’t hesitate to contact on : https://www.linkedin.com/in/mohdsabir

No responses yet