How to configure HTTPD and Py in Docker Container

Configuring HTTP services in Docker

We can configure HTTP services in docker in two ways. The first is by launching the docker container and then configuring it and the second method is more automated in which we write a Dockerfile and then build the container.

In this blog, we are going to launch the HTTP services by the second method. That is by creating a docker file.

To create a docker file we need a separate directory and then create a file named Dockerfile and then write the following code in it.

In this code, we have taken the centos:latest image as the base image and on top of it we are installing net-tools for some networking commands, httpd is the software provided by Apache for HTTP services and then we wrote a sample page ( “this is test file!!”) in the default directory( /var/www/html/index.html). And then at last we enabled the HTTP services by putting the command in /root/.bashrc file. We can build the docker file using the command

docker build -t httpd:latest .

At last, we need to launch a container with padding. REMEMBER it is the most important part. We need to launch the container with patting and expose it on port 80. We can launch the container with the following command

docker run -it --name <name> -p 1234:80 httpd:latest

Here, I have launched the docker container on port 1234 with the image httpd:latest( which we have created using the docker file).

Now our setup is completed now we need to visit our web page using our browser with the following URL:

http://<host_ip>:1234

Setting Py interpreter in Docker

Here also, we are going to configure the python interpreter using the docker file.

For this, we are taking the base os as centos:latest and downloading the python3 interpreter on it.

Now we need to build it

docker build -t python3:v1 .

That’s all we need to do. Our python3 interpreter is launched on the top of our container.

Hope you find this blog informative

Thank you for reading!!