Configuring Apache server on Docker container remotely using Ansible

Ansible playbook automation


Ansible is a simple automation language that can perfectly describe an IT application infrastructure. It’s easy-to-learn, self-documenting, and doesn’t require a grad-level computer science degree to read. Automation shouldn’t be more complex than the tasks it’s replacing.




A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.



Apache httpd Server

The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.


Apache httpd server

Project Objective

🔰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

Analysis and code


The above playbook uses a html file hi.html and sends it to the managed node and uses this file as the server home page. A httpd server was setup along with the SELinux firewall settings on a docker container, mynewos1, with a httpd docker image. The playbook on running gives the following output.


The server was exposed at port 8080, hence to visit the page, it is required to visit the IP address of the system followed by the port number 8080.

server page

This gives the basic example of an Apache server being set in a docker container remotely through Ansible automation.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Enable Accessibility

Everlane home page screen shot with “Enable Accessibility” feature in the top right corner

How To Install An App On My Mac

Introduction to Power Apps

How the SHA-2 (SHA-256) Hashing Algorithm Works

How to install Matomo on Ubuntu 18.04

GraphQL vs. RESTful

Unturned Update Patch Notes (Official) — January 7, 2022

Salesforce Spring ’21 — My Favourite New Flow Features

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
Abhiroop Bas

Abhiroop Bas

More from Medium

Install Docker and Docker-Compose on Linux

Grafana Alerts Json for beginners

Secure JupyterLab using Keycloak

Using MSBuild/VSBuild to prepare Docker image and deploy it to Azure App Service