AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Deploy Apache HTTPD on Docker Container with Ansible — Video Tutorial

Automate the deployment of Apache HTTPD in a Docker container using Ansible. Manage system packages, Docker images, and web content effortlessly.

Watch Video

Watch "Deploy Apache HTTPD on Docker Container with Ansible" on YouTube

What You'll Learn

Full Tutorial Content

How to Setup Apache Web Server in a Docker Container for Debian-like systems with Ansible? I'm going to show you a live Playbook with some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot. Setup Apache Web Server in a Docker Container for Debian-like systems - install packages => `ansible.builtin.apt` - docker py module => `ansible.builtin.pip` - pull image => `community.docker.docker_image` - document root => `ansible.builtin.file` - custom index.html => `ansible.builtin.copy` - run container => `community.docker.docker_container` Today we're talking about how to deploy a web server apache httpd in a Docker Container for Debian-like Linux systems. The full process requires six steps that you could automate with different Ansible modules. Firstly you need to install some python packages and dependencies using the `ansible.builtin.apt` Ansible module. Secondly, you need to install the Docker Module for Python using the `ansible.builtin.pip` Ansible module. Thirdly, you need to pull the image for the docker hub registry using the `community.docker.docker_image` Ansible module. Fourthly, you need to create the document root with the right permission with the `ansible.builtin.file` module. Fifty, you need to create the custom index.html with `ansible.builtin.copy` Ansible module. You could upgrade this step using the `template` module. Finally, you could run the `webserver` container setting the right port and volume settings using the `community.docker.docker_container` Ansible module. Links - [httpd image on docker hub](https://hub.docker.com/_/httpd) - [community.docker.docker_image](https://docs.ansible.com/ansible/latest/collections/community/docker/docker_image_module.html) - [community.docker.docker_container](https://docs.ansible.com/ansible/latest/collections/community/docker/docker_container_module.html) ## Playbook Setup Apache Web Server in a Docker Container for Debian-like systems with Ansible Playbook. code ```yaml --- - name: deploy httpd on container hosts: all become: true gather_facts: false vars: webroot: "/webroot/" tasks: - name: system packages present ansible.builtin.apt: name: - python3-pip - virtualenv - python3-setuptools state: latest update_cache: true - name: Docker Module for Python ansible.builtin.pip: name: docker - name: pull image community.docker.docker_image: name: httpd source: pull tag: latest - name: webroot present ansible.builtin.file: path: "{{ webroot }}" state: directory - name: custom index.html ansible.builtin.copy: dest: "{{ webroot}}index.html" content: | Custom Web Page - name: run httpd container community.docker.docker_container: name: webserver image: httpd state: started detach: true exposed_ports: - 8

About This Tutorial

Read the full written article: Deploy Apache HTTPD on Docker Container with Ansible

Topics Covered

Related Video Tutorials