Skip to content

Using Ansible-playbook lanuch docker container on worker node and run httpd container which is linked to local folder where put webpage & this container is exposed to world and then access web page from browser using ip and port number of worker node.

Notifications You must be signed in to change notification settings

Pratikshinde55/Ansible-Configure-webserver_inside_Docker_Container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 

Repository files navigation

Ansible-Playbook-LaunchDocker-container

🌟Configure webserver inside Docker by using Ansible automation🌟

Screenshot 2024-03-05 174420

For this Configuration I take two instance one for Ansible-Master node & Ansible-Target node, I use AWS cloud and EC2 instance is "Amazon Linux".

Screenshot 2024-03-05 173517

⚡prerequisites:

Ansible ssh configuration (set-up) master and target node must be done and ansible installed.

https://github.com/Pratikshinde55/Ansible-setup-onAWS.git (Use given link for ssh configuration)

NOTE:

For this configuration Ansible master node need Docker collection, and also install python3-pip .

Use this command to install Docker community collection:

   #ansible-galaxy collection install community.docker

Screenshot 2024-03-05 171855

On ansible master node i create workspace for this configuration named as "mycode" & create code(webpage) "Index.html" which deploy on apache webserver.

Screenshot 2024-03-05 173437

open or write ansible-playbook :

My ansible-playbook name is "myweb.yml" ,

NOTE: Ansible-playbook name must be in " .yml "

    #vim myweb.yml

💫Here some information about playbook tasks💫

  1. download docker package:

        tasks:
    
           - name: Install Docker
             yum:
               name: docker
               state: present
    
  2. start and enable docker service:

         - name: Start Docker service
           systemd:
             name: docker
             state: started
             enabled: yes
    
  3. Create a file which will add to my apache container create file in path /root/code :

    File module in ansible-playbook which help to create directory.

             - name: create file for adding container volume
               file:
                   state: directory
                    path: /root/code1
    
  4. Local code or local webpage copy:

    Copy module in ansible-playbook helps to copy my local master node code to target node dest: /root/code1 this destination is point 3 i have created

                 - name: copy local code or deploy webpage
                   copy:
                     src: index.html
                     dest: /root/code1
    
  5. Pull httpd image for docker container:

              - name: Pull httpd image from Docker Hub
                docker_image:
                  name: httpd
                  source: pull
    
  6. Launch Docker container using httpd image & exposed this httpd container for clients. Here i have atached volume to container this volume contain my webpage "index.html" from master node to Target node to docker httpd container:

              - name: Run httpd container
                docker_container:
                  name: my_httpd_container
                  image: httpd
                  state: started
                  exposed_ports: 80
                  ports:
                   - "8080:80"
                  volumes:
                   - /root/code1/index.html/:/usr/local/apache2/htdocs/index.html
                  restart_policy: always
    

Run ansible playbook :

  #ansible-playbook myweb.yml

Screenshot 2024-03-05 172636

❄️After ansible-playbook run successfully, on Target node Automation take place & configure our tasks .

Screenshot 2024-03-05 173327

⭐Now From Browser i can access my webserver :

On google - "< public ip of target node > : port no /index.html"

Screenshot 2024-03-05 173455

Also from my laptop command prompt: using "curl" command

Screenshot 2024-03-05 173048

About

Using Ansible-playbook lanuch docker container on worker node and run httpd container which is linked to local folder where put webpage & this container is exposed to world and then access web page from browser using ip and port number of worker node.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published