Launching Webserver inside a Docker Container Using Ansible

Task Description:->

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

  1. Configure Docker.
  2. Start and enable Docker services.
  3. Pull the httpd(Apache) server image from the Docker Hub.
  4. Run the docker container and expose it to the public.
  5. Copy the html code in /var/www/html directory and start the webserver.

What is Ansible ?

Ansible is an automation tool that is used for configuration management. It is a very powerful tool written in python language, it has thousands of modules using which it works, Ansible gets its intelligence from its modules.

Most of the Ansible modules have Intellisense in them, i.e. if the ansible code is executed once again, even then Ansible will first check that whether the operation has been performed or not, if yes, then that part of code will be skipped, otherwise it will be performed.

Steps to accomplish the Goal:

Note: For every task, check the name tag in the code, it explains the purpose of the code written before it. The code is written in YAML Language, in that language proper indentation is required.

  1. Create a Playbook file of Ansible.
  2. Check for Ansible Managed Node is accessible using Controller Node or Not.

3. Use command: “ansible-playbook docker.yml” to execute the playbook.

So Ansible Playbook Executed Successfully. Lets Verify The Things. (On Controller Node)

Docker is Installed, Started and Running…

We Can access the Webpage…

Here is Ansible Playbook.

Link For My GitHub Repo:

Thanks For Reading:)

--

--

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