Configure Webserver and Python Interpreter using Container - Docker

Configure Webserver and Python Interpreter using Container - Docker

What is Docker?

Docker container is an open source software development platform. Its main benefit is to package applications in containers, allowing them to be portable to any system running a Linux or Windows operating system (OS). ... While it is a major player in the container field, Docker is only one form of container technology.

No alt text provided for this image

In this article, I am going to show some tasks performing on the Docker Container which will help you to understand more about container technology

Tasks:

1)    Configure Webserver on the top of Docker Container

2)    Setting up Python Interpreter and running Python Code on Docker Container

Installing Docker: As I am using Redhat 8, so I need to first configure yum and create docker repo for installing the Docker.

 For this, go to the location, /etc/yum.repos.d and then create a file for configure yum and docker

No alt text provided for this image

Check the yum is properly configured or not using,” yum repolist”

No alt text provided for this image

Its working fine!

To install Docker-ce software, run

yum install docker-ce --nobest -y


No alt text provided for this image

I have already installed it before.

Finally, Docker installed successfully!

Start the Docker services using,

Systemctl start docker

Systemctl enable docker
No alt text provided for this image

--> We require ISO file for installing any operating system. In Docker, we have docker images for installing any container.

--> Go to docker hub and check for images

For Downloading any docker image, run

docker pull image_name:tag

To check the docker images

docker images


Here, I’m using centos.

No alt text provided for this image

1)    Let us configure the Webserver on the docker container…

--> Launching a new container

For launching a new docker container, command is

docker run -it -p local_port:docker_port -v volume:/directory --name os_name image:tag


Here

[ --name ] -> we use to assign a name to our container.

[ -v ] -> We use this to mount our local directory to docker container to store our files permanently. So, if somehow the docker container, our data will never be lost.

[ -p ] -> We use this to bind local port to docker port. So, this we can expose our container to outside world.

[ -it ] -> gives an interactive terminal to container, to perform any commands.

No alt text provided for this image

You can see, as I run the command, it gives a new interactive terminal for OS

To check, the container is successfully launched or not

We can also use ”docker ps” in new Redhat terminal

No alt text provided for this image

--> Let’s configure Webserver now.

Step1: Install httpd software using

yum install httpd -y
No alt text provided for this image
No alt text provided for this image

Step2: Put your code in /var/www/html

Using AWS CloudFront with docker!

What is Aws S3 & CloudFront?

In my html page, I have used the image present in Aws s3, To display that image I have used CloudFront URL

To Know more, visit my previous article:

https://www.dhirubhai.net/pulse/create-high-availability-architecture-aws-cli-anudeep-nalla/

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

Step3: Start the httpd services

Here, If we try to start services using systemctl command, it will be fail because docker doesn’t provide systemctl command.

So, Here we directly run the exec file location to run httpd server.

/usr/bin/httpd
No alt text provided for this image

Now let’s run IP:88/doc.html in the browser

No alt text provided for this image

But, the httpd service is temporary, After restart we have to start again.

To make the Service permanent

Open /root/.bashrc and write this 2 commands

rm -f /var/run/httpd/*

/usr/sbin/httpd
No alt text provided for this image

Let’s check, after restarting the container.

No alt text provided for this image

I’m using docker start and docker attach command for restart.

No alt text provided for this image

Its Works perfect!

Now we can save this docker container as image for testing/production environment.

Our Webserver is configured, we have to commit the image to save

For this, we have command

docker commit os_name image:tag
No alt text provided for this image

Our image is ready to use!

2)    Setting up Python Interpreter and running Python Code on Docker Container…

--> For this we can normally launch Docker container and install python3 to setup python interpreter.

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

Now you can write your code here.

--> But I want to create my own docker image, which launches python interpreter when I launch that image.

--> To create my own image, we have to use the concept of Dockerfile, By writing some code, we can make our docker images.

No alt text provided for this image
FROM centos:latest
 

RUN yum install python3 -y

 

CMD ["/usr/bin/python3"]

Save this code in a file named Dockerfile

Build the image using.

docker build -t mypy:v1 .
No alt text provided for this image

Lets run the image

No alt text provided for this image

--> To run the python file in the docker container, For this I have creating one new image

No alt text provided for this image
FROM centos:latest

RUN yum install python3 -y

WORKDIR /pycode

ENTRYPOINT ["/usr/bin/python3"]
 

CMD ["--version"]

Save the code in Dockerfile and run this command to build.

docker build -t name:tag .

No alt text provided for this image

Now Lets check the container is working or not

No alt text provided for this image

It works!

Thankyou

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

Anudeep Nalla的更多文章

  • How to Read RAM Data?

    How to Read RAM Data?

    What is RAM and What data it contains? Random-access memory (RAM) is a computer’s short-term memory. None of your…

    2 条评论
  • Zenity: Red Hat Enterprise Linux 8.4

    Zenity: Red Hat Enterprise Linux 8.4

    What is Zenity? Zenity is an open source and a cross-platform application which displays GTK+ Dialog Boxes in…

    6 条评论
  • OSPF (Open Short Path First) Routing Protocol implemented using Dijkstra Algorithm

    OSPF (Open Short Path First) Routing Protocol implemented using Dijkstra Algorithm

    Routing Information Protocol (RIP) RIP stands for Routing Information Protocol. RIP is an intra-domain routing protocol…

  • K-means Clustering and its use case in the Security Domain

    K-means Clustering and its use case in the Security Domain

    Introduction K-Means Clustering is an Unsupervised Learning algorithm, which groups the unlabeled dataset into…

  • JavaScript Use cases

    JavaScript Use cases

    What is JavaScript? JavaScript is a light-weight object-oriented programming language that is used by several websites…

  • Case Study on How Industries are using MongoDB.

    Case Study on How Industries are using MongoDB.

    What is MongoDB? MongoDB is one of the most popular open-source NoSQL database written in C++. As of February 2015…

  • Confusion Matrix role in Cyber Security

    Confusion Matrix role in Cyber Security

    What is a Confusion Matrix? A Confusion matrix is the comparison summary of the predicted results and the actual…

    1 条评论
  • GUI container on the Docker

    GUI container on the Docker

    Task 2 Task Description a) GUI container on the Docker b) Launch a container on docker in GUI mode c) Run any GUI…

    3 条评论
  • Deployment of Machine Learning Model Inside Docker Container

    Deployment of Machine Learning Model Inside Docker Container

    What is Docker? A Docker container is an open-source software development platform. Its main benefit is to package…

  • Create a Menu Using Python integrating with Ansible, Docker, AWS, Ansible

    Create a Menu Using Python integrating with Ansible, Docker, AWS, Ansible

    A) Output for Local Machine B) Output for Remote Machine Code is in GitHub:

社区洞察

其他会员也浏览了