CONFIGURATION OF WEB SERVER IN DOCKER USING ANSIBLE

CONFIGURATION OF WEB SERVER IN DOCKER USING ANSIBLE

In this article , you can learn to install docker and configure apache webserver inside docker container and expose the container . All steps are done by Ansible

????Task Description??

??Write an Ansible PlayBook that does the following operations in the managed nodes:

?? Configure Docker

?? Start and enable Docker services

?? Pull the httpd server image from the Docker Hub

?? Run the docker container and expose it to the public

?? Copy the HTML code in /var/www/html directory and start the webserver

Before start , first see about ansible, docker and apache webserver

Introduction :-

1. Docker :-

Docker is an open source containerization platform. Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

2. Ansible :-

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration .

3. Apache Webserver :-

  • Apache is an open-source and free web server software that powers around 40% of websites around the world. The official name is Apache HTTP Server is an open-source and free web server software that powers around 40% of websites around the world. The official name is Apache HTTP Server, and it’s maintained and developed by the Apache Software Foundation.
  • It allows website owners to serve content on the web — hence the name “web server.” It’s one of the oldest and most reliable web servers.
  • When someone wants to visit a website, they enter a domain name into the address bar of their browser. Then, the web server delivers the requested files by acting as a virtual delivery man.

Pre-requisites

  1. A controller node and one Managed node is configured. In the controller node, ansible is pre-installed.
  2. Now first let's create an inventory file. Where all the information about the target/Managed node will be stored. In the inventory file, we can store multiple IPs. Here I create one redhat 8 cli os as managed node .

Inventory file

No alt text provided for this image

Ansible-configuration file

No alt text provided for this image

Here host_key_checking=false [ used to auto accept ssh key by Managed Node]

command_warnings=False [disable command warnings]

deprecation_warnings=False [ to disable deprecation warnings]

Let' Started

First we can verify that our managed node is reachable or not

ansible all -m ping
No alt text provided for this image

Our system is working fine.

Now I create a playbook using ansible module to configure webserver on the top of docker

No alt text provided for this image


  • I Created a docker container  web3 and use Image httpd. The container will run in background by  detach option.
  • The container is exposed at port 80 on which webserver is running and forward container port 80 to base redhat 8 port 8080 .
  • We cannot directly login to container . So I mount base directory /root/WS of redhat 8 to container directory  /usr/local/apache2/htdocs ( location of webpages of httpd image) and directly copy webpage from controller node to managed node .

We can run playbook by

ansible-playbook docker.yml
No alt text provided for this image

After successful execution of playbook , paste Managed node IP: port ( 192.168.43.71:8080) in the browser ,you can see our webpages.

No alt text provided for this image

Note :- If you are unable to connect , then it may be firewall issue. So disable the firewall by command "systemctl stop firewalld".

Thanks,


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

Deepak Sharma的更多文章

  • Jenkins Dynamic Provisioning

    Jenkins Dynamic Provisioning

    Objectives In this article , We will see how we can create dynamic slave on the fly when job come and attach to the…

    1 条评论
  • OSPF Routing Protocol using Dijkstra Algorithm

    OSPF Routing Protocol using Dijkstra Algorithm

    Objectives:- In this article, We will learn about Dijkstra Algorithm and Open Short Path First(OSPF) Routing Protocol .…

    1 条评论
  • MongoDB Case study: Forbes

    MongoDB Case study: Forbes

    Objective In this article , we see how MongoDB Cloud Migration Helps World's Biggest Media Brand Continue To Set…

  • Vehicle’s Number Plate Detection using CNN model using python and Flask API…

    Vehicle’s Number Plate Detection using CNN model using python and Flask API…

    In this article, I am going to show you how you can create CNN Model or Deep Learning Model for Vehicle’s Number Plate…

    8 条评论
  • K-means Clustering and its real use cases in security domain

    K-means Clustering and its real use cases in security domain

    Objectives:- In this article, we will see about the Kmean algorithm and how Kmean algorithm helps in security domain to…

  • JavaScript:- Industry Use-cases

    JavaScript:- Industry Use-cases

    Objective In this article , we will learn about the JavaScript and the use-cases of JavaScript. How Industries utilizes…

  • Confusion Matrix and Cyber Security

    Confusion Matrix and Cyber Security

    Objectives:- In this article , we will see about confusion matrix and the use of confusion matrix . Also we see how…

  • Self-Reflection of MongoDB-Workshop

    Self-Reflection of MongoDB-Workshop

    # Day1 (1st May 2021) ?? Introduction of the file system? ??The data we will stored in file and that file we basically…

  • OpenShift case study:- Cisco

    OpenShift case study:- Cisco

    Cisco’s success depends on its ability to quickly deliver innovative IT products and solutions to customers. Delays can…

  • Industry Use cases of Jenkins:- Prepl

    Industry Use cases of Jenkins:- Prepl

    In 2021, When industries are running towards automation, adopting different DevOps tools to solve their industrial…

社区洞察

其他会员也浏览了