Launching webserver on container with ansible

Here we are going to see how we can launch webserver on docker container with the help of ansible

So what’s todays agenda see

🔰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 Ansible?

Ansible is an opensource software by Redhat this software is meant for configuration and management of different node. This also used for many purposes like provisioning also but mainly used for configuration management.

What is docker ?

Docker is containerization engine helps us to create containers for our various purposes. There are many other like crio,podman,rocket etc but docker is very famous among all. using containers we can launch any operating system in just fraction of second. docker uses images to launch container.

so lets directly understand the code.

Here in above image we are adding docker repository for linux machine then install the docker container with the help of yum command and then start the service. Also we need docker sdk for containers so we are downloading docker-py by pip3 command respectively.

Now we are pulling docker image for launching container and also disabling the firewall so that we can expose our webserver

Now we create folder to each container so that we can store the code for our website and we launch the container using the httpd image and expose by default 80 port to 8081 and attach the volume of “mywebserver” container to the “/webserver” folder.

Thank’s for reading🙌

you can connect me on linkedin 😃

you will find complete code on Github 💡



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
Abhishek Prasad Kesare

Abhishek Prasad Kesare


Data science, , cloud computing, Artificial Intelligence, Cybersecurity,tech-blogger