Docker - Setting up HTTPD Server and Python Interpreter
Image from Google

Docker - Setting up HTTPD Server and Python Interpreter

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 OS Kernel (Kernel of the Base/Host OS) and therefore use fewer resources than Virtual Machines. The fact the it borrows the kernel from the host OS makes provisioning of docker containers a matter of a second or two.

The software that hosts the containers is called Docker Engine.

Setting up Docker Engine

Base OS : Red Hat Enterprise Linux 8

  1. Configuring yum

/etc/yum.repos.d : Directory containing configuration files that define yum repositories.

No alt text provided for this image
  • Creating a new repo - adding baseURL to download Docker Software.
No alt text provided for this image
No alt text provided for this image

2. Installing Docker CE (Community edition)

yum install -y docker-ce --nobest
No alt text provided for this image

3. Starting Docker Engine

systemctl start docker

No alt text provided for this image

4. Downloading Centos docker image

docker pull centos

No alt text provided for this image

5. Launching a new docker container

docker container run -it centos

No alt text provided for this image

The above command instantly launches a new OS. The status can be checked by running the command given below.

(NOTE: This command is to be run in the Base OS (RHEL-8 in this case) and not inside the new docker container.

docker ps

No alt text provided for this image

Whenever a new docker container is hosted, a name is given to the new OS by default. (The name of the docker container in this case is frosty_tesla ). The name can be specified at the time of launching a new container by the given command.

docker container run -it --name <NameOfContainer> <ImageName>


Setting up HTTPD Server

  1. Installing HTTPD Server
yum install httpd

No alt text provided for this image

2. Adding a webpage code

/var/www/html is the directory containing all the webpages to be hosted on the server.

No alt text provided for this image

new.html is the webpage to be hosted.

3. Starting HTTPD Service

systemctl start httpd

No alt text provided for this image

The above command is the most generic way of starting httpd service. The systemctl command is a utility which is responsible for examining and controlling the systemd system and service manager. Whenever we boot a Linux OS, systemd is the first program that run automatically. But the case is not exactly the same in a docker container when it is launched. The systemd program is absent inside a docker container. Thus, it throws an error.

Let's examine "systemctl" command

(NOTE: The examination is done in the Base OS)

  • Every command is actually a program that run behind the scene as soon as we run the command in terminal. And every program is stored in a file before it can be run. Similarly, "httpd" command is also program which is stored in some file. This file is executed as soon as the command is run.
No alt text provided for this image

/usr/sbin/httpd is the file that is executed in order to start httpd service behind the scene. Thus, instead of "systemctl start httpd", this file can be directly run.

  • Every running process is provided with a process ID (PID).
ps -aux | grep "httpd"

The above command can be used to check the PID and other details of the httpd service when it is running. Also, this PID is stored automatically in a file every time the service is started.

No alt text provided for this image

/var/run/httpd/httpd.pid is the file which only contains the PID of the process.

  • To stop the service, the given command is run.
systemctl stop httpd

The above command actually goes to the directory /var/run/httpd and deletes all the files in it. Therefore, deleting files manually will also stop the httpd service.

No alt text provided for this image

4. HTTPD service made permanent

To make the service permanent, these two commands can be added to the file /root/.bashrc . (This file is executed automatically as soon as a docker container is launched. )

  • rm -rf /var/ruun/httpd/*
  • /usr/sbin/httpd
No alt text provided for this image

These changes are committed to create a new image of our own. After the new container is launched with this image, httpd service runs permanently,

No alt text provided for this image

Setting up Python Interpreter

  1. Installing Python3
yum python3 

No alt text provided for this image

2. Executing Python script

No alt text provided for this image


THANK YOU !!!


To view or add a comment, sign in

More articles by Shashwat Agarwal

Others also viewed

Explore content categories