Configuring Web server and Setting up Python on Docker

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 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


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 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 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.


# 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. Next, we are going to create a web page in /var/www/html folder named test.html
  2. 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

# 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 ☺

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store