Sitemap

Launching Webserver on the Top of Docker Using Ansible Play-book | Arth | Task-10 |

3 min readMar 21, 2021

Task-Description

🔹 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

Task-Steps

Step-1: Installing docker in linux is not very simple job. First we have to create a repo file for docker with given baseurl

https://download.docker.com/linux/centos/7/x86_64/stable/

Press enter or click to view image in full size

Step-2: There are some broken file in this base URL, so we can’t use package module to install docker. We can use command/shell module with “ nobest” option.

Press enter or click to view image in full size

Step-3: Now i am going to start the docker service.

Press enter or click to view image in full size

Step-4: It is important to install docker SDK before doing any docker operation from ansible.
Step-5: In this step I am going to pull http docker image.

Step-6: Create a directory and copy our code in this directory later we mount this to docker container’s document root.

Press enter or click to view image in full size

Step-7: Now launching a docker container.

Press enter or click to view image in full size

Here I gave 8080 port to expose the container & also mounted the volume.

Step-8: Now to expose the container for outside world we have to allow 8080 port in the firewall.

Press enter or click to view image in full size

Now lets run the play-book

Press enter or click to view image in full size

Let’s from the Target node that all tasks are completed or not.

Repository & Software check-

Docker service Status check-

Press enter or click to view image in full size

Docker SDK check-

Docker image & Docker Container check-

Press enter or click to view image in full size

Inspect Docker container-

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

Checking the active ports-

Press enter or click to view image in full size

Now let check our webserver is working or not.

Press enter or click to view image in full size

Yeppie it’s working
Our task is completed.

For code —

!!!Thanks For Reading the Article!!!

--

--