Docker with web server & python

Anirudh Bambhania
4 min readNov 12, 2020

Docker is a set of platform as a service 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. Let’s see how to integrate docker with python and apache web server.

Install Docker

First we need to install docker on our baseOS. For this we will need to configure yum repository so that we can download and install the docker. Go to yum repository by

cd /etc/yum.repos.d/

Now create a new repository by any name and type the following inside that repository.

[docker123]

baseurl=https://download.docker.com/linux/centos/7/x86_64/srtable/

gpgcheck=0

Now install docker by using the command

yum install docker-ce -nobest

This will install the docker community version. Now since we have successfully installed we have to start the docker service by

systemctl start docker

docker pull centos

docker run -it — name myos1 centos:latest

this will download and run the centOS docker conatiner.

Configure httpd webserver on Docker conatainer

First we need to install the httpd apache webserver in our docker container. Since apache packages comes pre downloaded into our centOS so we just need to install it.

yum install httpd

this will install the httpd apache webserver. Now go to html file location and create or upload different webpages to be hosted on our webserver.

cd /var/www/html

Now we need to start the httpd server . For this type

systemctl start httpd

if this command shows some error than don’t worry type

/usr/sbin/httpd

this will just give you a warning but will start our webserver. Now go to the browser and type “ ip/filename ” to open the html web page. And if you find any error while ifconfig command just install the net-tools package by “yum install net-tools”.

Running python code inside Docker

Similar to our webserver configuration we first need to install the python than we would be able to run all of our python codes inside the docker container. Just like httpd webserver, python packages also comes install in our centOS, so we just need to install it.

yum install python3

this will install the python3 and all of it’s dependencies. That’s it now just type

python3

to start python and run any python code.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Thank You

Anirudh Bambhania

--

--