?? Task 7.2: Configuring Apache Webserver & Python  on Docker Container

?? Task 7.2: Configuring Apache Webserver & Python on Docker Container

Task Description:

??Configuring HTTPD Server on Docker Container

??Setting up Python Interpreter and running Python Code on Docker Container

Let's see some theory part:

Docker:

Five years ago, Solomon Hykes helped found a business, Docker, which sought to make containers easy to use. With the release of Docker 1.0 in June 2014, the buzz became a roar. And, over the years, it's only got louder.

Docker is an open source platform which can be used to run/test applications in an isolated environment on the host system. Docker could be defined as an implementation of container using the concept of images.

Unlike VM which is a complete OS intalled on host system managed by hypervisors and needs dedicated resources from the host machine, docker uses Linux Containers which directly interacts with the linux kernel like any other process on linux to request resources.

No alt text provided for this image

Today, Docker, and its open-source father now named Moby, is bigger than ever. According to Docker, over 3.5 million applications have been placed in containers using Docker technology and over 37 billion containerized applications have been downloaded.



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.

Docker containers that run on Docker Engine:

  • Standard: Docker created the industry standard for containers, so they could be portable anywhere
  • Lightweight: Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs
  • Secure: Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry.
No alt text provided for this image

Docker Images:

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.

Docker images are also the starting point for anyone using Docker for the first time. A Docker image is made up of a collection of files that bundle together all the essentials, such as installationsapplication code and dependencies, required to configure a fully operational container environment.


Now Let's Start the practical :

Pre-requisite:

i.You must have the set-up of docker in your VM.

1.Pulling docker image

Here in this practical I am using ubuntu container image . For that we need to pull it first. By using the following command you can pull it.

# docker pull ubuntu

After the successful downloading, we get the latest tagged ubuntu image and we can launch container by using this image.

No alt text provided for this image

you can see here image downloaded successfully.

2. Launching container

Here i am going to launch container by using pulled ubuntu image.

No alt text provided for this image
# docker run -it --name Webserver -p 8080:80 ubuntu:latest

This command would get us an interactive container with the Webserver 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.Installing Apache Webserver in the container

But before going to install apache webserver , we need to update packages in reposirories by using "apt-get update" command.

In a nutshell, apt-get update doesn't actually install new versions of software. Instead, it updates the package lists for upgrades for packages that need upgrading, as well as new packages that have just come to the repositories.

No alt text provided for this image

After updating the packages, we can install any software.

Before installing apache webserver ,

No alt text provided for this image

You can check here , apache webserver is not downloaded.

Now , Installing Apache Webserver

Here I wanna tell you , for installing apache webserver, generally we hit " # apt-get install httpd " but sometime in repositories don't have desired packages. They provide some other packages which have included our virtual package.

like here i am goin to install apache webserver by using "apache2" package.

No alt text provided for this image

for installing it, we need to give our geo-location and time-zone.

No alt text provided for this image

Here I have selected 6 as a region code and 44 as my time-zone code.You can select as per your region and time-zone.

After that it downloaded apache2 webserver successfully.

No alt text provided for this image

Here you can see that apache server is successfully downloaded and /www/html directory comes up.

4.Starting apache2 services and status

No alt text provided for this image

You can check here , apache2 is running and it is active.

5.docker ps -a

when you hit this command , you will get entire info about created container it means its exposed port , name ,up time , id and many more.

No alt text provided for this image

you can see here exposed port . Go to the browser and give your local host public ip and container port like <host ip>:<container port>. In my case I have

No alt text provided for this image

When you see that page ..then you can conclude that your apache server is running well.


Now I am going to create one text file in /var/www/html directory.

No alt text provided for this image

this is the content in ls.txt file which is located in /var/www/html directory. After that make it executable by using chmod command and go to web-browser and give its path like <hostip:containerport/filename>

No alt text provided for this image

you can see here output come successfully.

6. Now i am going to install python interpreter

Sometime we need to update the packages again , while installing any software, just update it before installing any software , thats why error doeson't comes.

No alt text provided for this image
No alt text provided for this image

Here you can see that...python 2.7.18 is successfully downloaded . Now we can run our python program here by using python interpreter.

Here I am going to python interpreter and run some code.

No alt text provided for this image
No alt text provided for this image

Here python code run successfully .


Thank you for reading this article .....!!!!!!!!!!

I hope this article will helpful to you.

Komal Habura

Software Engineer

4 年

Great?

Onkar Naik

DevOps @Forescout ?? | Google Champion Innovator | AWS | DevOps | 3X GCP | 1X Azure | 1X Terraform | Ansible | Kubernetes | SRE | Jenkins | Tech Blogger ??

4 年

Nice work Nilesh Gopale ??

Shreyash Kotgire

Integration Developer @syngenta | Mulesoft | API Gateways | Finalist Microsft-BIAL Hackathon

4 年

Keep it up bro

Akanksha Tangade

Software Developer @FYNDNA

4 年

Good one Nilesh Gopale ???

要查看或添加评论,请登录

Nilesh Gopale的更多文章

社区洞察

其他会员也浏览了