Configuring apache server on Docker container and setting up Python interpreter
Hello and welcome to this article. Today we will learn how to configure an apache webserver in a docker container and also set up a python interpreter on top of it.
Its a simple process and we need to follow the following steps:-
- Launching a container with PATting
- Installing an apache server and enabling its services
- Installing python interpreter
Step 1) Launching container with PATting
Since our environment is inside the container so if we need to access the webserver running inside it then we need to expose the webserver port. And we do that by PATting which means Port Address Translation.
Since the outside clients can’t directly come to a webserver running in a container so we link the container’s IP and Port number with Base(Host) OS’s IP and Port number. and that's what PATting means.
Now launching container with PATting. Here I’ll be using ubuntu image but you can use any.
$ docker run -it --name web_server -p 8080:80 ubuntu:14.04
here, -p = port forwarding (host_port: webserver_port).
Step 2) Installing an apache server and enabling its services
Now we are inside the container and we need to install an apache product, so type the following command:-
a) For ubuntu :-
$ apt-get install apache2 -y
Now we need to start the apache services by the following command:-
$ /usr/sbin/apachectl start
b) For centos/fedora:-
$ yum install httpd -y
To start the apache services use the following command:-
$ /usr/sbin/httpd
Now you can put your webpages in /var/www/html folder.
If you are getting problem while installing apache, its probably because of DNS resolution. To solve it run following commands :-
$ firewall-cmd --zone=public --add-masquerade --permanent
$ firewall-cmd --zone=public --add-port=80/tcp
$ firewall-cmd --zone=public --add-port=443/tcp
$ firewall-cmd --reload
Step 3) Installing python interpreter
Now we will setup python3 on top of the container.
Installing python3:-
For ubuntu:-
$ apt-get install python3 -yFor centos:-
$ yum install python3 -y
Now our whole setup is complete. Our webserver is ready and python is also set up. So you can access web pages with your hostIP:port from browser like this:-
http://192.168.43.109:8080
I hope this article was helpful for you. If you have any problem with the above setup, you can contact me on LinkedIn. So that's it for this one and I’ll see you in the next article.
LIKE and SHARE!