Configuring Docker Container As WebServer Using Ansible

Configuring Docker Container As WebServer Using Ansible

>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
No alt text provided for this image

Now we create the ansible playbook in YML format:

No alt text provided for this image
No alt text provided for this image

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
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

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

docker ps
No alt text provided for this image

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

ip:port/file_name.html

要查看或添加评论,请登录

Ananya Jain的更多文章

社区洞察

其他会员也浏览了