AUTOMATING DOCKER WITH ANSIBLE

GOAL:

🔅 Configure Docker

🔅 Start and enable Docker services

🔅 Pull the httpd server image from the Docker Hub

🔅 Run the httpd container and expose it to the public

🔅 Copy the html code in /var/www/html directory and start the web server

LET’S BEGIN!

  • CONFIGURING DOCKER

— first for configuring docker we need to install docker community edition so we need to configure yum repository in our target node and as there is no module for docker in ansible we will use command module with following command:-

— now install docker-py library in our target node after that we create a folder in path /root/doc this directory is used to store an html file to test our docker image is working as server later

the playbook for these task is:

  • STARTING AND ENABLING DOCKER SERVICES

— use the service module to start the docker services

— now we need to pull an image from the docker hub in order to rum it on our docker container

  • STARTING THE CONTAINER

— for this example we are using httpd image from the docker hub to see if the image is working or not we will use ansible module to run our container

  • RUNNING THE HTTPD CONTAINER AND EXPOSING IT TO PUBLIC

— after creating the container we will use the firewalld module of ansible to expose it to public

— to test the container we will write its ip on our client computer

HENCE THE RESULTING WEB PAGE WILL BE:-

OUR DOCKER HTTPD CONTAINER IS CONFIGURED

--

--

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