Friday, December 8, 2023

Docker Swarm

Why?

Docker is a great tool (the "de facto" standard) to build Linux containers.

Docker Compose is great to develop locally with Docker, in a replicable way.

Docker Swarm Mode is great to deploy your application stacks to production, in a distributed cluster, using the same files used by Docker Compose locally.


What are Docker and Docker Container?

Docker is an open-source tool used to automate application deployment in the form of lightweight containers. And Docker containers are not only lightweight but also make the application platform-independent. So, the application that runs on your computer will run the same way on your friend’s computer!

Docker Container logo


The Docker Containers overcome a lot of problems faced by the virtual machines. Docker Containers are faster, portable, provide isolation, use less memory, etc.


If you have Docker installed, you already have Docker Swarm, it's integrated into Docker.

You don't have to install anything else.


docker info 








































Now, that is inactive, we will make it active.

Drawbacks of Containers

If I am running million of containers, then we need to maintain it .








Scale Out:

Out/In/Up/Down:

How much we use, that much only we pay. 


Ensure that Containers are recreated, if they fail.

Replace Containers , without down time(Deployment)

Tracking:

We need to track control , where and when they get started.


Scalability


In the below pic, we can see, if the load is more on one of the server, than it should automatically switch to next server. 
We should not depend on the single server.











































































































































Now, go to AWS account and create a instances
























































































Once all the instances are created. We need to login into MoboXTerm.


Now, Add Six instances of it.




























Now, go to each instances of AWS and then paste it hear























Rename each of the instance in the aws account with the below names




 



























Click on Connect and paste each instance id in the moboxterm 
















Repeat the same in each of the instances.



































After running all the instances, next step is to check 
























Installing parallelly in  all the machines.









































Next, we can rename all the tabs.











Now, in manager 1 Tab, 

To activate docker swarn, 








When ever we are fried , than the first node becomes the leader(manager)























Before running add worker and add manager, let us check how many nodes are running.







Now, you can run the instances and re run the docker node ls command



Next step is copy the add worker node and run in the worker 1, worker2, worker 3 instances.
















Now, re run the docker node ls command









Similarly add worker node 2, and worker node 3 and re run the docker node ls command in the manager instance


Note: docker node ls -->Should always run on the manager node.













From the above screen shot, we can see that one manager node and three worker nodes have been created.



After that, we want to add a manager, for that , copy the add a manager command and run in the manger2, and manager 3 instances




















































Now, go and check the status of Docker Swarn

Type docker info now





































































































Now, go to the manager 1 instance and kill it. 


docker swarn leave command is used , so that the manger 2 will become active now























Now, fire docker node ls in the second manager instance and see the difference





































Saturday, December 2, 2023

Docker Compose Example 3 (Custom Network)

 






version: "3"

networks:

 ibm:

  driver: bridge

 oracle:

  driver: bridge

services:

  web:

   image: nginx

   container_name: my-nginx

   networks:

    - ibm

   ports:

    - 80

  database:

    networks:

      - oracle

    image: redis

    container_name: my-db



Next run the docker compose command


docker-compose -f example3-docker-compose.yaml up -d

























































































































docker-compose -f example3-docker-compose.yaml down



Let us do another example with volumes

version: '3.8'
services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html
  db:
    image: mysql:5.7
    volumes:
            - mysqldb:/var/lib/mysql

volumes:
  wordpress:
  mysqldb:









docker-compose -f example8900-dc.yaml up -d



























docker ps







# docker-compose -f example8900-dc.yaml ps







docker images








 





docker volume ls















 ls /var/lib/docker/volumes/root_wordpress/










ls /var/lib/docker/volumes/root_wordpress/_data









docker exec -it d396d243a4ba bash






















Next type env


Variables, which we have created , we will be able to see 

















































Similar you can check for other container

Run that container by using docker exec command

























Now, Login into AWS Cloud and add the port Numbers




























Next step, go back and copy the public IP Address

and browse that by using public ipaddress:8080






































Select the language of your choice


















Give the site url . Enter the details and click on Install WordPress


Next step, you should be able to login with your site url

































You  can create a post, upload media files, Look n feel, comments and other things








Friday, December 1, 2023

Docker Compose -Example 2

 





















vi example2-dc.yml

Write the below code

version: '3'
services:
 web:
  image: nginx:1.19
  container_name: test1
  ports:
   - 86:86

 database:
   image: redis:latest
   container_name: my_db
   ports:
     - "5432:5432"





Giving Permissions.



chmod +x /usr/local/bin/docker-compose


























































Python -3

  Lists It is used to store Collection of data. Lists are created using square brackets: List Items Order cannot be changed. It can have dup...