Configuring Docker Container As WebServer Using Ansible

Ananya Jain
2 min readMay 2, 2021

>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 web server

Before we start, we first have to configure ansible.cfg and inventory file!

And we have controller Node with IP address 192.168.43.67 and manage node with IP address 192.168.43.137 . Let’s check the connectivity between the hosts:

ansible all -m ping

Now we create the ansible playbook in YML format:

We can also check the syntax of playbook named docker.yml:

anisible.playbook --syntax-check docker.yml

Now Let run the playbook:

ansible-playbook -v docker.yml

Playbook runs successfully!! Now, lets check whether httpd container is running or not in the Managed Node

docker ps

Now we can view the Web Page by entering the ip-address with the file name:

ip:port/file_name.html

--

--

Ananya Jain

Google Cloud ACE Certified | Google Cloud Student Mentor | Operation Team @Amazon Alexa Community | Aviatrix Certified Engineer | Machine Learning enthusiast