How to configure Web server on docker using Ansible-Playbook

Hola Everyone, Today I am going to show how to configure an Apache web server on docker using Ansible-playbook.

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

🔹start the webserver

We will write an Ansible-playbook for:-

  1. Downloading docker-ce package
  2. Then, start the docker service
  3. Then, we need to install the docker python interpreter using the docker-py package.
  4. We pull the httpd image from docker hub
  5. Launch the container using httpd image
  6. Then create a directory, then create an HTML file.
  7. Then we copy html file into /usr/local/apache2/htdocs

See the below image for the Ansible-Playbook Code.

Process of performing the above steps:-

1) Run the ansible-playbook by using ansible-playbook docker-conf.yml command. See the below image.

2) Now, we are checking some steps in the Managed Node.

a) docker ps → docker is running

See the below image.

b) we have created the ekansh.html file already.

See the below image.

c) Now, we are going to check that our ekansh.html file has copied or not.

Enter inside the docker → docker exec -it webserver bash

Then run, cd /htdocs, the file is present.

See the below image.

Then, we paste the URL on google, the output will come.


The below image shows the output.

I am a blogger. Check my blog →