Configuration of Apache Web-server on Docker Container and Setting up Python Interpreter & running python code on Docker Container

Farheenn
4 min readMar 13, 2021

Pre-requisites: A pre-installed docker software on top of Rhel 8.

In this task I am going to:

  1. Launch a docker container on Virtual Machine.
  2. Configure Apache web-server on docker container.
  3. Set up Python Interpretter and run a python code on a docker container.

1. Launching a Docker Container

To Launch a docker container on Redhat8 our basic requirement is to start the docker services on Redhat8.

we can start the docker services using a command:

#systemctl start docker

To check the status we can use the command:

#systemctl status docker

After starting the Docker services, we will launch a docker container from the centOS image and name it as my_os.

This will successfully launch our container. We can also confirm the containers launched from our Base OS that is the host system using the command:

#docker ps

The Container is successfully launched!

2. Configuring Apache webserver on Docker container

Apache webserver is usually known as httpd server as httpd is a product of Apache. To configure webserver on any OS (Operating System) we can follow a simple 3 step configuration method:

step1: Installing the required software

To setup the apache webserver we need the software “httpd”. So, we will install it in our docker container my_os.

We don’t have a pre-installed ‘httpd’ software so let’s install it using yum command:

#yum install httpd

Now our docker container has httpd software to setup the httpd server.

step2: Configuring Document root

Httpd servers/Apache webservers have a pre-defined folder ‘/var/www/html’ which is exposed to the outside world as we start the webservices. This folder is known as ‘Document root’. All the html files have to be inside the document root so as to be accessible by the clients/users of the website/webpage. To configure the document root we will either copy the pre-existing html files or create new ones inside the document root.

We can go inside the document root by using change directory command:

#cd /var/www/html

And then create a new html file ‘web.html’ using vi text edittor and write some html code inside

#vi web.html

Now our document root has an html file with a couple of lines of html code. After configuring the document root we will start the webservices.

step3: Starting webservices

Usually on Rhel8 we use a command ‘systemctl’ to start, enable or stop any services. Inside the docker container launched from centOS image this command is not applicable. So, to start the web services we use the command:

# /usr/sbin/httpd

After starting the webservices, we can connect to the webserver and access the webpage using the ip of the webserver. To fetch the ip we use the command:

#ifconfig

However, ifconfig command is not found in the centos container. To use this command we need to install the software ‘net-tools’ which provides the command ifconfig.

#yum install net-tools

After installing net-tools, we can fetch the ip and search the URL on firefox from the baseOS.

http://172.17.0.2/web.html will land us to the webpage.

Therefore, the Apache webserver (httpd server) is successfully configured on docker container!

3. Setting up Python interpreter on Docker Container

To setup the python interpreter we can install the python3 interpreter using yum command.

#rpm -q python3 shows that we don’t have a python3 interpreter pre-installed.

To install the python interpreter we use the command:

#yum install python3

After installation of python3 interpreter we can run any python code on top on our docker container.

Therefore, the python3 interpreter is successfully setup on top of the docker container.

Thankyou for reading my article!!

--

--

Farheenn
0 Followers

23. Engineer and Technophile.