LAUNCH APACHE WEBSERVER INSIDE DOCKER CONTAINER USING ANSIBLE

shristi sharma
3 min readDec 20, 2020

--

TASK DESCRIPTION:

Using Ansible Playbook We Will Configured docker and start the apache services.

👉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 files and start the web server.

Rough Overview What We Are Going To Do:

step 1: Create a docker yum repository.

step2: Install docker by using yum command.

step3: Create a workspace on target node where our code will be copied by managed node

step4: Start the docker services

step5: Pull the httpd image(because by pulling httpd image it will done our half work automatically like starting apache services inside the docker).

step6: Launch docker container and expose it to the port number(you can choose any port number of your choice).

Requirement:

✔One Managed Node

✔One Target Node

📍In this practical managed node and target node both are configured on local os(RHEL8)

CREATE AN ANSIBLE PLAYBOOK WHILE CONSIDERING THE ABOVE STEPS

Create an inventory which includes IP address of Target node and also update the configuration file of ansible playbook

vim /root/ip.txt

Always check the ansible connectivity to confirm nodes connectivity.

ansible all -m ping

Create a workspace in managed node where you will write all ansible playbook code I have created workspace name ws7 and my playbook name is webserver.yml . In this one index.html file has also been created

FINAL PLAYBOOK CODE

- hosts: all
tasks:
- name: “Docker”
yum_repository:
name: docker
description: “Software from docker”
baseurl: “https://download.docker.com/linux/centos7/x86_64/stable/"
gpgcheck: no

- name: “Install Docker-ce”
command: “yum install docker-ce — nobest -y”

name: “creation workspace on target node”
file:
path: /root/ansiblewebos
state: directory
— name: “copying content into target node”
copy:
src: “index.html”
dest: “/root/ansiblewebos/”
— name: “starting docker daemon”
service:
name: docker
state: started

- name: “pulling httpd docker image from hub”
docker_image:
name: “httpd”
source: pull
- name: “starting docker”
docker_container:
name: “shristios”
image: httpd
state: started
detach: yes
interactive: true
ports:
- “1234:80”
volumes:
-/root/ansiblewebos/:/usr/local/apache2/htdocs/

PLAYBOOK OUTPUT

LETS SEE TARGET NODE

As we can see ansiblewebos directory has been created and also index.html page has been created in our target node

Lets run some docker commands in our target node⏩

Check the status of the docker in the target node

systemctl status docker

docker images (to see our httpd image that we pull )

docker ps (to see all running container thaat we launched with the help of docker pull command)

DOCKER PS

YES APACHE WEBSERVER HAS BEEN SUCCESSFULLY CONFIGURED

Now checked the webpage from the webbrowser using syntax👇

IP(TARGET NODE): PORT NO

webserver launched on docker container

BY -Shristi Sharma

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

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

shristi sharma
shristi sharma

Written by shristi sharma

Aspiring Devops Enthusiastic |Content Creator |Python | Machine Learning | Cloud Computing

No responses yet

Write a response