Configure Apache Webserver on Docker Container with help of Ansible Playbook

Akshay Gupta
2 min readMar 26, 2021

AIM:

  1. Setup and Configure Docker.
  2. Start and enable Docker services.
  3. Get the httpd server image from the Docker Hub.
  4. Launch the httpd container and expose it to the public.
  5. Copy the html code in the/var/www/html directory and start the webserver.

PREREQUISITE

  1. Two Yum configured Linux-based OS.
  2. Download ansible in master node and configure inventory file Hosts.

Setup and Configure Docker.

Firstly we will configure yum repository for docker in target node for downloading docker and then we will Install docker and will start docker service and Then we will start and enabled the Docker Service.

Now we install the pip3 command or can say python3 libraries to download docker software development kit (sdk) for integrating docker with ansible.

Get the httpd server image from the Docker Hub

Now we get the httpd from docker hub using ansible playbook and copying your html file to docker.

Launch the httpd container and expose it to the public

Now we download httpd server image from docker hub and will copy content for website in /var/www/html file. And then we have to expose our container so everybody can see our webpage.

Now Run the Playbook after put all above steps.

Here’s the playbook

Now if we try to connect with container IP and we see the web page i.e index.html with Output HTTP server on docker which we have written in index.html.

This is the Final Setup to Launch a Webserver on Docker Using Ansible.

Thank You

--

--