Hello everyone, you all might have seen the power of docker, a container managing software by directly. But to use it with remote systems isn’t an tedious task when you have to configure same type of configuration in different-different flavours of OS’s
Yes it is tedious task so, in this article I would like to explain how to use ansible a configuration management tool, to manage docker.
The pre-requisites are that you should have ansible configured on the system and you are all set.
The task is as below :
🔹 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
Now, let’s write task for for configuring the docker,
- name: Docker repository conf
description: desc for docker
Checking if docker is already present
- stat: path=/usr/bin/docker
this task will install the docker library of python
- name: install python3 docker sdk
Installing docker via yum it will not install if it is already installed
- name: install docker
command: "yum install docker-ce --nobest -y"
when: not docker_present.stat.exists
Now finally starting the docker service
- name: start service for docker
Creating a folder on the host docker container so that later we can transfer the files from there to the container
- name: "Creating folder in docker host"
Copying the files from the controller node to the managed node
- name: "Copying the files in the host system"
Finally creating and starting the container from the httpd image of docker
- name: "Creating OS from httpd image"
We have now successfully launched the webserver on top of docker. to see whether it is a success or not go to the managed node and type the following command.
docker inspect <name of image> | grep IP to get the IP address of container
curl <IP> to access the content of web page
Thanks for reading 🔥🔥😊😊