Webserver Configuration using Ansible and Docker

  • Configure and start Docker Services.
  • Pull apache httpd server image from DockerHub.
  • Run the docker container and expose it to public.
  • Copy the html code in document root .
  • Start the webserver.

Ansible Architecture:

Docker:

#to install Ansible
pip3 install ansible
#to install sshpass
yum install sshpass
#to check the version of Ansible installed in the system
ansible --version
output
<ip address> ansible_user=root ansible_ssh_pass=<password> ansible_connection=ssh
#to open ansible configuration file
vim /etc/ansible/ansible.conf
Ansible Configuration file
#to check the list of managed nodes
ansible all --list-hosts
#to check the connectivity
ansible all -m ping
Connectivity
#to create a playbook
vim docker_task.yml

Playbook contents:

Playbook Configuration
ansible-playbook docker_task.yml
Playbook execution output
  1. Docker configuration status in managed node:
systemctl status docker
Status of Docker services in managed node
docker images
Docker images
docker ps
list of active containers
  1. Using the the IP address of the container.
#command to find the IP of container
docker inspect webserver1 | grep IP
here the IP address is 172.17.0.2
http://<ip address>:8080/index.html
Final webpage accessed using Mozilla Firefox using Container IP address

Link to the source code:

--

--

--

Final Year Undergrad from Indian Institute of Information Technology Ranchi interested in learning the ins and outs of Technology

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

Recommended from Medium

What I learnt from 3 software developers

Creating Infrastructure (Launching OS/Instance on AWS Cloud) using Terraform & configuring…

Step how to setup streaming replication slots postgresql-11 ubuntu 18.04

The best resources for passing the GCP Associate Cloud Engineer exam

Lessons from building Code for Canada’s Civic Tech Toolkit

Support the Entire HTML Spec with Macros

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
Akshansh Singh

Akshansh Singh

Final Year Undergrad from Indian Institute of Information Technology Ranchi interested in learning the ins and outs of Technology

More from Medium

How to mount a host directory in a Docker container? — Devops Mania

The Host Network Driver | Networking in Docker #5

Reverse Proxy Feature of NGINX Server

Basic Load Balancer using nginx container