Configuring Apache Webserver & Python on Docker Container
Before understanding this , we have to understand what is docker?
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.
Now the question arise what is container?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
What is image?
A Docker image is a read-only template that contains a set of instructions for creating a container that can run on the Docker platform. It provides a convenient way to package up applications and preconfigured server environments, which you can use for your own private use or share publicly with other Docker users.
Now we start the practical demo!!!!!!!
You must have the docker set-up in your System.
1.Pulling docker image
first we have to pull the image . In this practical I am using ubuntu container image. we use the following command to pull the image:-
docker pull ubuntu
2. Launching container
Now we have to launch the container . we use the following command to launch the container:-
docker run -it --name myserver -p 8080:80 ubuntu:14.04
This command would get us an interactive container with the myserver container name and maps the port.
-t : assigns a terminal inside the container.
-i : create a interactive connection with container by grabbing STDIN.
-p: maps the host’s 80 port with 8080 port of container
We would need the 80 port of host machine to be mapped with the 8080 port of our container since we would be using host’s public ip and 8080 port to take in requests and host would forward these requests to the Apache web server running at port 80 of container.
3.Update the Packages
we need to update packages in repositories by using apt-get update command.
4.Installing Apache Webserver in the container
Now we have to install Apache Webserver. we can install it by using the following command:-
apt-get install apache2
5.Starting apache2 services
Here we can see that the Apache webserver is start.
Now , Go to the browser and give your local host public ip and container port like <host ip>:<container port>.
when we see this page it means that our server is running .
Now I am going to create one text file in /var/www/html directory.
Here i created a file name “ls.txt” . after making the file go to web-browser and give its path like <hostip:containerport/filename>.
6. Now install python interpreter
Now we have to install python interpreter , we can use the following command to do this
apt-get install python
we can check the version of python by using “python -V” command.
Now I am going to python interpreter and run some code.
Here we can see that Python Program runs.
I hope you like this article.
For Furthur Queries, Suggestion’s Feel Free to Connect with me On Linkedin.