Configuring Web server and Setting up Python on Docker

Nupur Sogani
5 min readNov 23, 2020

--

Docker logo

In this article we are going to complete a task in which we have to :

🔅 Configure httpd server on Docker Container and

🔅 Set up Python interpreter and run python code on Docker.

So, Let’s start with first knowing what is a Container?

Containers are an executable unit of software in which application code is packaged, along with its libraries and dependencies, in common ways so that it can be run anywhere, whether it be on desktop, traditional IT, or the cloud.

Containers are small, fast, and portable because unlike a virtual machine, containers do not need include a guest OS in every instance and can, instead, simply leverage the features and resources of the host OS.

Benefits of Container :

🔹 Lightweight : They are small in size as compared to virtual machines as they share the machine OS kernel.

🔹 Portable and platform independent : Containers carry all their dependencies with them hence they need not be re-configured across systems.

🔹 Supports modern development and architecture : Containers are an ideal fit for modern development and application patterns — such as DevOps, serverless, and microservices

🔹 Improves utilization : They improve CPU and memory utilization of physical machines

Containerization

Software needs to be designed and packaged differently in order to take advantage of containers — a process commonly referred to as containerization.

When containerizing an application, the process includes packaging an application with its relevant environment variables, configuration files, libraries, and software dependencies. The result is a container image that can then be run on a container platform.

Containers vs Virtual Machines

Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.

Containers

Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.

Virtual Machines

Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries — taking up tens of GBs. VMs can also be slow to boot.

Docker

🔸 Docker, launched in 2013, is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.

🔸 Docker is the de facto standard to build and share containerized apps — from desktop, to the cloud. It is built for developers.

🔸 Docker’s friendly, CLI-based workflow makes building, sharing, and running containerized applications accessible to developers of all skill levels.

🔸 It is installed from a single package to be running in minutes.

Task

Now, lets start docker daemon (services) in our system.

# systemctl start docker

We can download docker images from docker hub. Here in this practical we are going to use image of CentOS, for which we have to run the following command -

# docker pull centos:latest

We can check what all docker images we have in our system by :

# docker images

Next, we are going to launch an OS with pre-downloaded docker image of CentOS and name it task_os

# docker run — it — — name task_os centos

We can check that our new container has been successfully launched by cmd

# docker ps

Configuring web server on docker

  1. Installing ‘httpd’ software to configure Apache Web Server by # yum install httpd command.
  2. Next, we are going to create a web page in /var/www/html folder named test.html
  3. Now, we have to start httpd services.

To start the httpd services in docker, we run the following command :

# /usr/sbin/httpd -k start

Take the ip address of this docker container and paste it in the browser of our local system along with file name and there we can see the content of our html web page.

Hence we have successfully configured Apache Web Server on our docker container.

Setting up python interpreter and running python commands

Firstly, we will have to install python in our instance using :

# yum install python3

Now, our python interpreter is ready to use

We can run python code from file also as:

!!! Task completed !!!

Thank you for reading ☺

--

--

No responses yet