How to Setup an Apache Web Server & python interpreter in a Docker Container

Mihir Patel
4 min readNov 11, 2020

--

1) Set up Web server:

Task details:

Configure HTTPD server on docker container so we can use as web server.

Let’s start :

  1. Install docker
  2. configure web server in docker container

👉 Install docker

step 1: We need to configure first yum file

first go to /etc/yum.repos.d then create docker.repo file .

In docker.repo file add following things:

[docker]

baseurl= https://download.docker.com/linux/centos/7/x86_64/stable/ gpgcheck=0

and save file.

Run the following command to check docker repo working or not

yum repolist

step 2: We can install docker by following command

yum install docker-ce — nobest

docker will install

👉 configure web server in docker container

Note: Before starting service you need to stop the firewall so you will not face any connectivity issue inside docker

Step 1:start docker service

systemctl stop firewalld

To start docker service use the command

systemctl start docker

see status by

systemctl status docker

step 2:Pull image and run docker image

Pull image by following command

docker pull centos

Launch container using centos image by following command

docker run -it — name mycentos1 centos

Then you automatic enter in centos terminal

Now , we Going to install httpd server in centos container

  1. install httpd in centos by

yum install httpd

2. Now run following command to start httpd

/usr/sbin/httpd

3.Now put file in /var/www/html folder

Now see ip of container by command

ifconfig

If this ifconfig not work then install net-tools software by following command

yum install net-tools

ip of this container is :(172.17.0.3)

Now go to browser then type

http://172.17.0.3/html1.html

Now successfully run our server You can see html page on browser.

2)Setting up Python Interpreter and running Python Code on Docker Container

Task details:

Run python on any docker container

step 1: First pull image and run container

docker run -it — name pythoncontainer centos

Here run is used for pull and run image can both.

Now automatic landed on centos container.

You can run any container same as centos by following command

docker run -it — name pythoncontainer CONTAINER_NAME

Here we use centos image container for run python

step 2: Run python

In redhat os , python3 is inbuilt so we can use directly but in container not pyhton3 is inbuilt.

So we need to install python3 software

Before install python3 : we will show command not found

To install python3

yum install python3

Now We add python3 in our centos container

Run python code:

Conclusion:

how we can python code & setup Web server in any container .

Thank you

--

--

Mihir Patel
Mihir Patel

No responses yet