Ansible Playbook that will retrieve the IP of Docker Container and Update the IP in the inventory file so that further configuration of Web Server could be done inside that container.🧐🧐

First of all, by default, any docker container does not have ssh enabled i.e we can’t log in inside the docker container. We need to create ssh enabled docker image so that we can configure the webserver inside it using Ansible Playbook.😇😇

We can use Docker commit as well Dockerfile for creating ssh enabled docker image.

So for the above Here is the Dockerfile that can be used to create such an image.

Run the command to build docker image: docker build -t upmanyu13/centos_ssh:v1( Give the name of the image according to yourself)

Now the ssh enable image is successfully build and We can push it to Docker Hub by using the command: docker push <image-name>

Now we can use the above ssh enable the image to launch Docker Container using Ansible Playbook. 😎😎

Below is the Ansible Playbook which will launch the docker image, Retrieve the IP of the container and Dynamically add it to the inventory file.

Run the above playbook which will launch the Docker Container, Retrieve IP, and Update in the inventory.

So after running playbook, docker container is launch and IP inventory gets updated after retrieving the Ip of Container.

Below is the ansible-playbook which will further Install the Web Server and Start the Web Service inside the Docker Container.

Run the above playbook which will configure the webserver inside the container.

So finally we can see Web Server is successfully started.😍😎

Thank you for reading the article. 😇😇