Sitemap

Deploying Web Server and setting up Python Environment on the Docker Container.

4 min readNov 22, 2020
Press enter or click to view image in full size

šŸ”˜Goal for this blog:

šŸ”…Configuring HTTPD Server on Docker Container

šŸ”…Setting up Python Interpreter and running Python Code on Docker Container

So Let’s Start

šŸ”…Configuring HTTPD Server on Docker Container:

I am going to launch an ec2 instance on AWS cloud on the top of which we are going to install the docker

Press enter or click to view image in full size
Press enter or click to view image in full size

I have successfully login to our instance using Putty.

Now i am going configure yum repository for installing the docker-ce, to do this first i have to go /etc/yum.repos.d directory, then i have to create a file with .repo extension .

Here in my case i have created docker.repo file in which i have written the following things:

Press enter or click to view image in full size

Now we have successfully configured the repo for docker, to install the docker we have to write the command :

#yum install docker-ce — nobest

Press enter or click to view image in full size
Press enter or click to view image in full size

Now docker is successfully installed on the top of ec2 instance.

to check this we have #rpm -q docker-ce command

Press enter or click to view image in full size

Now we have to start the docker service using systemctl command:

#systemctl start docker

Press enter or click to view image in full size

Next step is to download the docker image of Centos OS:

Now to pull the image we have the command:

#docker pull <image name>

Press enter or click to view image in full size

Next Step is to Launch the container:

for this we have the command;

# docker run -it — name webserver centos:latest

Press enter or click to view image in full size

ifconfig command doesn’t pre-installed here. So we can ask yum that which software provides us ifconfig command :

Press enter or click to view image in full size

So we need to install the net-tools software to use ifconfig command.

Press enter or click to view image in full size

we can run ifconfig command to know our IP address.

Press enter or click to view image in full size

šŸ”“To Configure Apache httpd webserver on docker container we have to follow certain steps :

1ļøāƒ£Install httpd software

2ļøāƒ£Put the webpages in /var/www/html

3ļøāƒ£Start the Service

Step-1: Install httpd software

To install httpd software, run #yum install httpd command inside the docker container.

Press enter or click to view image in full size

Step-2:Put the webpages in /var/www/html

we have created an html file web.html

Press enter or click to view image in full size
Press enter or click to view image in full size

Step-6: Start the HTTPD Service

Normally to start the service we always use systemctl start httpd command. But in docker container by-default systemctl command doesn’t work. Here to start the service we use /usr/sbin/httpd

To check that we have successfully started the service, we can run the command #netstat -tnlp if it shows port 80 then the service is started.

Press enter or click to view image in full size

šŸ”…Setting up Python Interpreter and running Python Code on Docker Container:

To setup Python Interpreter we have to install python3 in the container, for this we have the command :

#yum install python3

Press enter or click to view image in full size

Now we can run the any python code on the system by run command

#python3

Press enter or click to view image in full size

Thanks

For any Query ping me on the LinkedIn:

Connect with my mentor: Mr. Vimal Daga

--

--

No responses yet