Open In App

How To Install Docker Using Ansible Playbook ?

Docker is a software platform that allows you to build, test and deploy applications that use OS-Level virtualization to deliver software in packages called “containers”. Containers – Docker package software into standardized units called “Containers”. Docker is a stand-alone tool. which means no need to install run-time. The manner in which we make, convey, and oversee programming applications has been totally changed by Docker. An incredible asset packs applications into lightweight, convenient compartments, making it simpler to construct, boat, and use them.

What is Docker?

Docker infrastructure consists of – client (docker build, dicker pull, docker run), docker host (docker daemon, containers, images), Registry (images as snapshots)



Docker consists of a client server, Docker host, and Registry. Initially, with the help of client-server we need to install docker and start, and enable the docker services. Then, we can to build the images with the help of a dockerfile by using the docker build command.



Now, from the client server the pull request is sent to the Docker host, where the docker Daemon is the engine of the docker receives the request and the docker engine sent this request to registry {i.e; Docker-Hub, where the images are stored}. From the registry, it takes the required image and sent back to the docker host and pulls the images, and runs the container with the help of the images. inside these containers, the applications runs.

Key-Concepts of Docker

Primary Terminologies

Docker

Docker is a platform that empowers developers to develop, test, and run applications in containers. containers are lightweight, convenient, and isolated conditions that package applications and their conditions. Docker gives tools and APIs to building, managing, and deploying containers productively.

Ansible

Ansible is an open-source automation tool utilized for setup the management, application deployment, and task automation. It utilizes YAML-based playbooks to depict the ideal condition of frameworks and executes tasks on remote hosts over SSH. Ansible improves on infrastructure management via automating repetitive tasks and ensuring consistency across environment.

Inventory

A stock in Ansible is a document that characterizes the rundown of hosts and groups of hosts that Ansible will make due. It can be written in INI or YAML, and it can be static or dynamic. The stock document indicates the association data, (for example, IP addresses or hostnames) for each host and puts together has into groups for more easier administration.

Playbook

A playbook in Ansible is a YAML file containing a set of instruction (tasks) that define the ideal condition of remote hosts. Playbooks are utilized to automate tasks like programming installation, configuration, and support. There are one or more plays in each playbook that specify the hosts to target and the actions to take.

Module

Ansible’s modules are small programs that carry out particular operations on remote hosts. Ansible gives many underlying modules for normal tasks like package management, file manipulation, and administration control. Modules are executed by the Ansible engine on the target host and convey the outcomes back to the control node.

Task

An task in an Ansible playbook is a single unit of work that characterizes an activity to be performed on a remote host. Tasks can carry out actions like installing packages, copying files, or restarting services in a sequential manner. The module to be used and the parameters needed to carry out the action are specified in each task.

Step-by-step process to install docker using ansible playbook:

Launch two EC2 Instances, one is master and another one is slave. with the help of master-slave configuration, we need to install docker package into slave instance through, master instance.

Step 1: Launch an instance

$cd /etc/ → $ ls (check for ansible..) if it is not installed

Step 2: Install Ansible

$sudo amazon-linux-extras install ansible2
$cd /etc/ → ls → cd ansible → sudo vi hosts

Step 3: Create Playbook

$ mkdir playbooks

$sudo vi package.yml

Step 4: Run the Playbook

$ansible-playbook package.yml

Step 5: Verify

Conclusion

Taking everything into account, introducing Docker on track has with Ansible has number of benefits, including versatility, consistency, and productivity. Structure heads and DevOps gatherings can streamline the association of Docker across different circumstastand-aloneAnsible playbook – FAQ’s

Why utilize a playbook while introducing Docker on Amazon Linux, and what is a playbook?

A playbook is like a recipe/script that tells Ansible how to set up your servers/instances. We use playbooks for Docker foundation to computerize the cooperation, committing it speedier and less error slanted.

Could I at any point involve playbooks for Docker establishment without knowing how to code?

Actually, no! The language used in playbooks (YAML) is straightforward and direct, easy to understand. You basically need to follow the means outlined in the playbook.

Can I modify the Docker establishment procedure with a playbook at any time?

Absolutely! Playbooks are versatile, so you can transform them to suit your necessities, according to prerequisites. Do you want to set up more advanced settings or install specific versions of Docker? Playbooks work on things.

Might I anytime present Docker on Amazon Linux without a playbook?

Despite the fact that it is feasible to physically introduce Docker, utilizing a playbook will save you time and exertion, especially assuming you have a ton of servers.

What occurs on the off chance that something turns out badly during a playbook-based Docker establishment?

Ansible is smart enough to handle mistakes and retries naturally. If something goes wrong, it will let you know so you can fix it.

On Amazon Linux, how would I execute a playbook to introduce Docker?

It’s basically pretty much as straightforward as running a single request! Basically tell Ansible where your servers are and which playbook to use, and it wraps up.


Article Tags :