Configuring HTTPD server in Docker container using Ansible

WHAT IS ANSIBLE ?

Ansible is a configuration management system written in Python using a declarative markup language to describe configurations. It is used to automate software configuration and deployment.

WHAT IS DOCKER ?

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 ship it all out as one package. The Docker daemon is a service that runs on your host operating system. Docker container is an open source software development platform. Its main benefit is to package applications in “containers,” allowing them to be portable among any system running the Linux operating system (OS). Docker Hub is a cloud-based registry service which allows us to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker Cloud so we can deploy images to our hosts.

WHAT IS WEBSERVER?

A web server is a computer that runs websites. It’s a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP).

In this article, we are going to setup Apache server over a docker container using Ansible.

STEPS TO DO THIS TASK :

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the httpd container and expose it to the public

🔹 Copy the html code in /var/www/html directory and start the web server.

First we have to create VM for Controller Node and Managed Node.

Lets begin the implementation with setup of Ansible:-

Step 1. Install Ansible and check the version of Ansible

Step 2. Create an inventory file i.e. group of IPs in /root/ip.txt in which we have to write the Target Node IP as a host in Controller Node.

Step 3. Configure the Ansible

To configure ansible, create a directory named ansible in /etc directory then create the ansible configuration file i.e., ansible.cfg

Step-4: Now, we are good to create our playbook to run the code

Here I have created playbook named task10.yml

Step-5: We have to assign the following tasks in the playbook

a) Configure Docker

b) Start and enable Docker service

c) pull the httpd server image from docker hub

d) Run the docker container and expose it to the public

e) Copy the html code in /var/www/html directory and start the web server

Step 6. Now create a HTML file

Step-7: Run the playbook before launching the container in the target node

Step-8: Give the target ip with the filename in the browser

So here we can see that our webservices have successfully started.

Hence the task is successfully completed

Thankyou!!

--

--

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