Configure and Expose “Docker” with the help of one of the best automation tool “Ansible”


1.Configure docker

2.Start and enable docker services

3.Run the docker container and expose to the public

4.copy the code in /var/www/html/ directory and start the webserver

now we are going to use ansible for all the steps described in this task.

For doing all the configuration i used the ansible-playbook shown below :

key points of this ansible playbook :

  1. i used yum_Repository ansible module to configure the docker
  2. after configuring the docker , i used package and service module to install and starting the services of docker
  3. then for running a container i am using my own preconfigured docker image “sshcentos” , because ansible use ssh protocol to connect to the target node and in this image ssh is already enabled so further tasks can be implemented inside the docker container
  4. now after running a container ansible will update the container’s IP in the [docker] group in its host file so further tasks can be done inside that container

Lets start and run the PLAYBOOK

this is my inventory file and we can see this inventory file doesn’t contain any information about any container

we can run the ansible playbook with this command

#ansible-playbook docker.yml

as we can see playbook run successfull and everything is configured fine and we can also see the information related to the newly launched container is also updated in the inventory file

now we can check that our container is exposed to the outside world with the help of docker host IP and port number 8082 because at the time of launching the container i exposed the container on port number 8082

Now finally docker is configured successfully with the help of ansible

So , I hope you enjoy my this article and you learn some new concepts




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store