webserver setup on docker container using ansible-playbook
Agenda: Configure web server inside a docker container using ansible-playbook.
To do this we have to follow certain steps:
step:1 Adding docker repository.
step:2 Installing docker package.
step:3 start docker service
step:4 Installing python docker library.
step:5 Pulling docker httpd image which is available on docker hub.
step:6 Making a folder at the target node.
step:7 copying HTML file from the controller node to the target node folder.
step:8 Launching Docker container using httpd image.
→ Here using the exposed_ports keyword I have specified at which port service web service will run.
→ here using the ports keyword we are specifying the Port NATing. Because no one from outside cannot connect inside the docker container because it having private IP. But with docker host anyone can connect so we run the docker proxy program on port 8222 whenever the client hits to <docker-host-ip>:8222 it will do port NATing and connect to docker container <docker-container-ip>:80.
→ Using volumes keyword we are specifying the /usr/local/apache2/htdocs/ inside docker container is attached with target node folder /ansible/ whenever any changes inside docker container /usr/local/apache2/htdocs/ in this folder will same as changes at /ansible/ folder. In this step, we are doing this because in case if we lost the container important data inside docker container keep with us. And When launch the same container we can attach this folder and get data back and again start the service.
Here are screenshots of the playbook:
After the run of the playbook, I have captured some screenshots from the target node to understand step8.
→ Using command netstat -tnlp I got to know docker proxy service is running on port 8222. And the process number is 4730.
→ Here at the target node, I am seeing the information about process 4730.
From the outside world, no one can connect to the docker container but whenever the client makes the request on <docker-host-ip>:8222 this proxy program will transfer the request from the docker host to the docker container <container-ip>:80. Because the docker host only having a direct connection with the docker container.
Github Link:
https://github.com/Laveenajethani/webserver-setup-on-docker-contaier-using-anisble-playbook