How to Install httpd web server and Python Interpreter in Docker Container

Deepak Sharma
5 min readDec 14, 2020

--

In this article, I am going to make a great setup which is really helpful to take the next step in containerization technologies. We gonna Install Docker Container on top of RHEL8(It is the base Operating System where we install Docker). We will make our own container more advanced by running httpd server and a python interpreter.

What is Docker?

Earlier whenever we have a requirement to launch an Operating System to perform some experimental tasks or some work, we need to install it as we usually do!!! That takes 20–30 minutes (approx.) and resources as well. So in industry use cases, there are many situations where we need to install the Operating System 5–10 times or maybe more. Isn’t it a great loss of time ?? It is obvious that we cannot compromise with the resources, but Time is the most important thing and if we are wasting time then we are wasting money !!!!

For this problem, a great person named “Soloman Hikes” created a great tool in the year 2013 that is capable of installing and preparing a fully working Operating System instance to operate and execute some programs. The wonderful thing with this tool is — It will launch and setup everything within 1 sec or maybe less Isn’t it exciting !!

Implementation -:

STEP-1: Create Docker.repo

  1. Go to the link and copy this.
  2. Open your terminal and run this command “cd /etc/yum.repos.d/” to go this path.
Go to path

3. After reach, this path creates a new file “docker.repo” and paste the link which you copied. For better understanding see the below image.

Create docker.repo file
Put URL for docker repository

STEP-2: Install Docker

To install docker we use this command “yum install docker-ce — nobest — allowerasing” , nobest and allowerasing use for install all dependencies which necessary for docker installation.

Install Docker

After install, we check the docker service active or not???. To check status we use “systemctl status docker” command.

Docker status

Docker service is not active yet…..

so lets active docker service..

For temporary stary(means stop service after reboot) we use “systemctl start docker” command.

For a permanent start(means services never stop even reboot) we use “systemctl enable docker” command.

To enable docker services

STEP-3: Pull the required image(OSI image)to create a docker container

As our requirement is to execute a python program, so need to add/pull an image that can support python!! Here I am going to use the centos:7 image.

To pull a docker image, we use the command “docker pull centos:7

This downloading may take some time, depends on your internet speed.

To check the available images, we use the command “docker images”.

STEP-3: Pull the required image(OSI image)to create a docker container

As our requirement is to execute a python program, so need to add/pull an image that can support python!! Here I am going to use the centos:7 image.

To pull a docker image, we use the command “docker pull centos:7

This downloading may take some time, depends on your internet speed.

To check the available images, we use the command “docker images”.

Successfully downloaded centos:7 image

STEP-4: Run a container with a centos operation system

To launch the Docker container we use the docker run command. — name tag we use to assigned names to the container.

Successfully launched the container

STEP-5: To install httpd webserver

We use “yum install httpd -y “ to install httpd webserver.

httpd web server installed

After successfully installed we need to start httpd service so for start any service we use “sytemctl start docker” But in the docker container, systemctl command isn’t work

For start httpd service we use “ /usr/sbin/httpd” command.

To start httpd server

STEP-5: Create HTML file

  1. First run this “cd /var/www/html” to go Document root directories.
  2. In this directory, we create a file i.e “task7.2.html”
Create HTML file

STEP-6: Install ifconfig command software

In docker container ifconfig command is not available we have to install that using software which name “net-tools”

Se for install, we use “yum install net-tools -y “ to install ifconfig command.

Install net-tools for ifconfig

After that, we need to know the IP address because using the IP addresses we can see HTML file n the browser.

To check container ip address

See the HTML file in the browser using “IP address/filename” in our case “172.17.0.2/task7.2.html”.

Webpage

→Now we install Python Interpreter in a docker container.

  1. First, install python interpreter using yum command i.e. “yum install python3”

2. After that create a python file for testing and run it.

……

this article is published by deepak sharma…

thanks for reading..

--

--