CONFIGURING HTTPD SERVER AND PYTHON INTERPRETER IN DOCKER .

Himanshu Yadav
3 min readMar 14, 2021

Docker is a software platform for building applications based on containers — small and lightweight execution environments. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.

On the other hand a Docker container image is an executable package of software that includes a lot of different things to run like code, runtime, system tools, system libraries and settings.

To perform this task a system must have docker installed. We can check running container using :

docker ps

First we create a container :

docker run -it — name name_of_container imagename

Now we install httpd server on our Container.

yum install httpd

After installing we have to start the server and then enable it for which we use

Systemctl start httpd
Systemctl enable httpd

But systemctl doesn’t work in a container.

So we start our server using :

/usr/sbin/httpd

we can check our service and its port using :

netstat -tnlp

and also we put a webpage to serve in /var/www/html folder.

But After starting if we close our container and then again start it httpd service stops. Its because httpd service is not enabled.

So to make our httpd service permanent we have to make it start every time we start our container and for that we can write its start Command in the script file which always runs on starting the os.

/root/.bashrc

We write /usr/sbin/httpd Command in .bashrc file but then again if we start our container our httpd service doesn’t run its because when we start our httpd service it creates some files for this service with unique pid and when we close our container these files still remain in that location and when we again restart our container and service they can’t create new files. So we have to delete those files while restarting our service

rm -rf path_of_files

so we put both commands in .bashrc file.

Now we can see our service is running and we can access the webpage and see the content.

Python Interpreter in Container :

To run a python interpreter inside a container we first create a container and run following command

yum install python3

and to use the interpreter we can run :

python3

Which gives us a REPL to perform our tasks.

So now we have created two containers one with a httpd service running and another with a python interpreter.

THAT’S IT.

THANK YOU.

TASK #7.2

--

--