Configuring web server and setting up python interpreter on the top of docker container
Harshita Kumari
DevOps Engineer | Terraform/RHCSA/AWS/Azure Certified | AWS,Docker, Ansible, Kubernetes ,Terraform ,Python ,Jenkins,
Docker & Docker Containers
Docker is a containerization platform that packages your application and all its dependencies together in the form of a docker container to ensure that your application works seamlessly in any environment. Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
Docker Container is a standardized unit which can be created on the fly to deploy a particular application or environment. It could be an Ubuntu container, CentOs container, etc. to full-fill the requirement from an operating system point of view. Also, it could be an application oriented container like CakePHP container or a Tomcat-Ubuntu container etc. It leveraged existing computing concepts around containers and specifically in the Linux world, primitives known as cgroups and namespaces. Docker's technology is unique because it focuses on the requirements of developers and systems operators to separate application dependencies from infrastructure.
?? TASK DESCRIPTION :
??Configuring HTTPD Server on Docker Container
??Setting up Python Interpreter and running Python Code on Docker Container
First, Configuring HTTPD Server on Docker Container--
Step 1 : Installing the docker first
Command : yum install docker-ce --nobest
Step 2 : Starting the docker services
Command : systemctl start docker
Docker services started--
Command : systemctl status docker
Step 3 : Pulling the image - For launching the container, we need to pull the image. Here we are pulling centos image
Command : docker pull centos
Step 4 : Launching the container with centos image
Command : docker run -it --name <container_name> <image_name:image_version>
Step 5 : Installing httpd software on the top of container
Command : yum install httpd
Step 6 : Creating a html file named page.html in the /var/www/html folder
Step 7 : Starting httpd services
We can check whether the services started or not by running netstat -tnlp command. For running this command we need to install net-tools software.
Generally, "systemctl" command is used for starting services but "systemctl" command is not supported in containers. So no service started with port 80. This can be seen by running the Command : netstat -tnlp
So "/usr/sbin/httpd" command is used for starting the httpd services in the docker container.
Now, httpd services started with port 80.
Step 8 : Deploying the html file on the browser
URL : https://172.17.0.2/page.html
Setting up Python Interpreter and running Python Code on Docker Container--
Step 1 : Installing the python software
Command : yum install python3
Step 2 : Creating and running python code inside the container
- Python interpreter can be launched by running the Command : python3, here you can run any python code. Also can create a python code file inside the container and can run it using the Command : python3 <filename>
- Another way is that you can create a python code file inside the container and then create the image of this container. So this container image will already contain the python code file. So now can directly run this python code file using the python3 command while launching a new docker container with this created image.
Creating image of the launched container which already contains the python file--
Command : docker commit <container_name> <image name:version>
The image "myhttpd_image" created, can verify by the Command : docker images
Now, directly running the python code file while launching a new container with the created image- "myhttpd_image".
Command : docker run -it --name <container_name> myhttpd_image:v1 python3 <filename>
It gives the output of the python file.
Thank You for reading..!!