Configuring HTTPD Server on Docker Container using ansible

Himanshu Agrawal
3 min readMar 23, 2021

🔰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 /usr/local/apache2/htdocs/ directory
and start the web server

First step is to create a inventory file and enter manage node IP : /root/ip.txt

We need to add our inventory file to the ansible configuration file /etc/ansible/ansible.cfg

Configure yum repo

Start and enable Docker services

Install the Docker SDK for Python for Python 2.7 or Python 3 as follows:

$ pip install docker

For Python 2.6, you need a version before 2.0. For these versions, the SDK was called docker-py, so you need to install it as follows:

$ pip install 'docker-py>=1.10.0'

Create a directory that you can mount to container volume .

Pull the httpd server image from the Docker Hub

Run the docker container and expose it to the public and Copy the html code in /usr/local/apache2/htdocs/ directory and start the web server

run playbook :

ansible-playbook docker.yml

Check whether the container is running or not by running the command in that node

docker ps

now we check our server : 192.168.185.6:8080

ThankYou

My LinkedIn: Himanshu Agrawal

--

--

No responses yet