š Docker Task :
š Configuring HTTPD Server on Docker Container
š
Setting up Python Interpreter and running
Python Code on Docker Container
Lets gets insight about the tools which are to be used inside this task
What is Apache Web Server?
Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web. Itās widely thought that Apache gets its name from its development history and process of improvement through applied patches and modules but that was corrected back in 2000. It was revealed that the name originated from the respect of the Native American tribe for its resiliency and durability.
What is Docker?
Docker is a Linux-based, open-source containerization platform that developers use to build, run, and package applications for deployment using containers. Unlike virtual machines, Docker containers offer:
- OS-level abstraction with optimum resource utilization
- Interoperability
- Efficient build and test
- Faster application execution
Docker mainly comes in two editions Docker Community Edition or Docker Enterprise Edition.
Docker CE is a free and open source containerization platform. It is a rebranded version of the Docker open source solution that has been freely available since the launch of Docker in 2013.
CE can run on Windows 10 and Mac, on Azure and AWS, as well as CentOS, Debian, Fedora, and Ubuntu. CE can be downloaded directly from the Docker Store.
Docker EE, on the other hand, is a premium version of CE. Docker EE is an integrated, fully supported, and certified container platform that runs on Red Hat Enterprise Linux (RHEL), SUSE Linux Enterprise Server (SLES), Oracle Linux, Ubuntu, Windows Server 2016, as well as Azure and AWS.
First things first, itās important to note that Docker CE is not a āwatered downā version of Docker EE. Both CE and EE have the same core features and functions.
Both editions offer the same core features, Docker EE comes with additional features that can help enterprises launch, manage, and secure their containers more efficiently.
Both editions are updated quarterly (although Docker CE users can expect āEdgeā updates, discussed further herein), and both are available on a wide range of popular operating systems and cloud infrastructures, giving enterprises the freedom to run containerized applications on their favorite infrastructure ā without lock-in.
Components of a Docker architecture
Docker comprises the following different components within its core architecture:
- Images
- Containers
- Registries
- Docker Engine
Images
Images are like blueprints containing instructions for creating a Docker container. Images define:
- Application dependencies
- The processes that should run when the application launches
You can get images from DockerHub or create your own images by including specific instructions within a file called Dockerfile.
Containers
Containers are live instances of images on which an application or its independent modules are run.
In an object-oriented programming analogy, an image is a class and the container is an instance of that class. This allows operational efficiency by allowing to you to multiple containers from a single image.
Registries
A Docker registry is like a repository of images.
The default registry is the Docker Hub, a public registry that stores public and official images for different languages and platforms. By default, a request for an image from Docker is searched within the Docker Hub registry.
You can also own a private registry and configure it to be the default source of images for your custom requirements.
Docker Engine
The Docker Engine is of the core components of a Docker architecture on which the application runs. You could also consider the Docker Engine as the application thatās installed on the system that manages containers, images, and builds.
A Docker Engine uses a client-server architecture and consists of the following sub-components:
- The Docker Daemon is basically the server that runs on the host machine. It is responsible for building and managing Docker images.
- The Docker Client is a command-line interface (CLI) for sending instructions to the Docker Daemon using special Docker commands. Though a client can run on the host machine, it relies on Docker Engineās REST API to connect remotely with the daemon.
- A REST API supports interactions between the client and the daemon.
Developing with Docker
Developing apps today requires so much more than writing code. Multiple languages, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage creates enormous complexity. Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.
What is Python Language?
Python is a widely used general-purpose, high level programming language. It was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with an emphasis on code readability, and its syntax allows programmers to express their concepts in fewer lines of code.
Python is a programming language that lets you work quickly and integrate systems more efficiently.
There are two major Python versions: Python 2 and Python 3. Both are quite different.
Why Python?
- Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
- Python has a simple syntax similar to the English language.
- Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
- Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
- Python can be treated in a procedural way, an object-oriented way or a functional way.
Lets dive into the task:
NOTE : This task is performed in Linux OS.
STEPS TO PERFORM THE TASK :
š¹ Configure Docker
š¹ Start and enable Docker services
š¹ Download the httpd server using the Yum command
š¹ Deploy some static webpage on the server
š¹ Start and enable Httpd services
š¹ Check whether webpage is running or not
š¹ Download the Python interpreter using the Yum command
š¹ Launch the interpreter and run some program file
Install Docker on the top of Linux :
Firstly you have to configure the yum to install the docker if you are doing this practical on your local VM or system, but if you are doing this practical on AWS instance then you need not to configure the yum as AWS provide the preconfigured yum to us.
Now run this command to install the docker-ce version.
yum install docker-ce --nobest
Start and enable Docker services :
Now run this command to start the docker services
systemctl start docker
Run this command to check the docker services is successfully started or not
systemctl status docker
After Installing Docker Now we are Ready to move Further.
Download the Docker Image used for the Container :
Run this command to pull the image from Docker Hub :
docker pull {image_name}:{tag}
In My Case I have Used Centos Image, You can Use any
After downloading the image is saved in your local registry and you can check your all images from the command,
docker images ls
Launch Docker Container :
The command is,
docker container run -it centos:7
Now after launching the container we have to install the HTTPD software using yum command. By default docker also gives the preconfigured yum, so you donāt need to configure it.
Deploy some static webpage on the server :
We have to deploy our code in the default Document Root of Httpd Server i.e /var/www/html/ folder and the file in which we write our code should have html extension. So Iām writing the only HELLO WORLD in my webpage file and when we access it , it only prints the HELLO WORLD which shows that our webserver is working successfully inside the Docker Container.
Start and enable Httpd services :
There are lots of ways in Linux to start the services , one of the way is āsystemctl commandā and one way we know, in hadoop(Big Data) we also start the Namenode and Datanode, but there we had not use systemctl command, there we use āhadoop-daemon.sh start Namenode/Datanodeā. So if you ask āhadoop-daemon.shā command what you do? they say I also start the services, which one? Masternode or Slavenode. But this command do not have the capability to make your service permanent enabled. So not all command through which you start the services have a capability to make your service permanent enabled at the boot time. So systemctl is one of the command that has a capability to use a āenableā option to make your service permanent enabled.
But the problem here is when you run service respective command inside the docker container through which your service start, wonāt work, why? The reason is by default the Docker doesnāt allow it. Lets try it in dockerā¦ā¦
It doesnāt show any error with command not found like this, it means command is there but they are not supporting.
So we know that when we run the systemctl command behind the scene they run this file ā/usr/lib/systemd/system/httpd.serviceā and this file finally run this command ā/usr/sbin/httpdā. So finally this is the command which start our service, so in docker or in centos we can directly run this command to start webservices.
Download the Python interpreter using the Yum command :
Now we can download the python interpreter using yum command,
Launch the interpreter and run some program file :
SO HAVE SUCCESSFULLY COMPLETED OUR TASK
Thanks For Readingā¦ā¦.