Configure WebServer on the Top of Docker Using Ansible

Vineet Negi
3 min readDec 14, 2020

Task Description📄

🔰Write an Ansible PlayBook that does the following operations in the managed nodes:

🔹 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

What is Apache HTTP Server ?

The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software

What is Docker ?

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

Let’s get Started

To check weather the target node is ping able or not.

command :- ansible all -m ping

  1. Configure Docker

First we need to get the software / package of docker then install the docker

2. Starting and Enabling the Services of Docker

3. Downloading Apache HTTP Image from Docker Hub

4. Creating directory for storage as it’s clearly mention the by default location is /usr/local/apache2/htdocs/ as in my case its not there.

If u run webserver with this location u’ll get output something like this “ IT WORKS”

5. Now to run Docker Container using Ansible we need install library as its mention in the ansible documentation.

package name -: docker-py ( ansible ansible is built over python so it supports python libraries)

6. Now Launch the container and expose it’s port (8080)

NOW LET’S RUN PLAYBOOK

Now Let see the Output

Sign up to discover human stories that deepen your understanding of the world.

Vineet Negi
Vineet Negi

Written by Vineet Negi

★ Aspiring DevOps Engineer ★ Technical Volunteer @LinuxWorld ★ Technical Content Writer @Medium ★ ARTH Learner

No responses yet

Write a response