training.shoppinpal.com
  • Introduction
  • 1. The Ideal Workspace
    • The Perfect Machine
      • For Biz Team
      • For Developers
      • For Designers
    • Setup a machine in the cloud
      • Solution
      • Setup box on Azure
        • Create a machine on Azure
        • Test drive your remote machine
        • Setup Dropbox On Azure
      • Setup box on DigitalOcean
        • Setup UI
        • Shared FileSystem
          • Dropbox
            • Use locally developed node modules in another project
          • sshfs
        • Long Running Sessions
      • Feedback
  • 2. Learning Git
    • Static Code Analysis
  • 3. The Backend
    • Use Containers
    • Setup a loopback project
    • Lockdown
    • Build a better mousetrap
    • The abyss stares back
    • Built-in models
    • Extending built-in models
    • Understanding UserModel
    • Boot Scripts
    • Promises
    • Find roles for current user
    • Loopback Console
    • Current User
  • 4. Multi-tenancy With Loopback
    • What is Multi-Tenancy
    • Architecting with Loopback
    • Define scope for Roles
    • Role Resolvers
    • Access Control For Tenants
    • Better Programming with multi-tenancy
  • 5. The Frontend
    • The Browser
    • Unit Testing
      • Motivation behind this blog
      • How to write a test
      • Karma and Jasmin
      • Writing Tests
    • End-2-End Testing
    • Angular 1.x
    • Angular 2
      • Testing
  • 6. ElasticSearch
    • Better Search with NGram
    • NGram with Elasticsearch
    • Fun with Path Hierarchy Tokenizer
    • Working with Mappings and Analyzers
  • 7. Promises
    • What are Promises
    • Promise Implementations
    • Nuances
    • What should we use
  • 8. Learning Docker
    • Docker Swarm
  • 9. Queues & Workers
    • PHP workers in AWS EBS
    • NodeJS workers in AWS EBS
      • SQS Daemon by AWS
      • SQS Daemon in NodeJS
      • SQS polling by worker
    • Gearman
  • 10. Docker
    • Capabilities
  • Appendix
    • Bug in WebStorm deployments
    • The Perfect Terminal
    • Scalable App Deployment with AWS
    • Chrome Tips & Tricks
    • Host your own Gitbook
    • Gitbook Tips & Tricks
    • How to handle support incidents
    • Dev Resources
    • Debug e2e Tests on CircleCI
    • Logging
    • Authentication Principles
    • Mac
    • nvm
    • Unify testing with npm
      • Debugging Mocha
    • Sequence Diagrams
    • Project Sync via IDE
      • SFTP with WebStorm
      • SFTP with Visual Studio
    • Soft Linking
    • NodeJS Profiling
      • How to find node.js performance optimization killers
    • Setup Packer on Azure
Powered by GitBook
On this page
  1. 8. Learning Docker

Docker Swarm

Previous8. Learning DockerNext9. Queues & Workers

Last updated 7 years ago

A Docker swarm is a cluster of machines, all running docker which provides a scalable and reliable platform to run many containers.In this tutorial, we will be looking at how to setup a docker swarm.

Note : Steps are documented below the video.

Requirements :

  1. Setup at 4 droplets on DigitalOcean.

  2. Install docker(version 1.13) on each droplet using this shellScript.

  3. Name the droplets as numbers. for eg. swarm-00,swarm-01..so on.

References used in this tutorial :

Steps :

  1. Clone the Github repository in your local system using command :

    git clone https://github.com/Bhushan001/docker-swarm-html.git

  2. Now you can go into the directory using:

    cd docker-swarm-html

  3. Now you will need to copy file install.sh to all of your droplets using command.

    scp install.sh root@ip_address:/root/install.sh

  4. after copying install.sh from local to droplets, you can install docker by executing script using :

    ./install.sh

  5. After successfully installing docker, you will need to setup docker swarm.

  6. Log in into one of the droplets using ssh as

    ssh root@ipaddressof_droplet

  7. To create docker swarm, run

    docker swarm init --listen-addr ip-address-of-droplet:2 --advertise-addr ip-address-of-droplet

    this will initialize the docker swarm on this system and make this droplet as a swarm manager. This command will also generate a joining token for other droplets to join the swarm. copy that command and run it on each of the other droplets so they can join this swarm.

  8. For example, after copying the generated command, you can login to any other droplet in the subnet using ssh and run this command. After doing this, that droplet will join the docker swarm as a worker and the swarm will look like this.

  9. You can use

    docker node ls

    to check how many nodes are there in the docker swarm.

  10. Now you will need to deploy a service in this docker swarm.run the command

    docker service create --name website --publish 80:80 bhushangadekar01/docker-swarm-html

    This will create a service in docker swarm from docker image bhushangadekar01/docker-swarm-html and run it as a container on port 80.

Now you will be able to see your website running on port 80 of any of the droplets. wait.. we deployed this service on only one droplet so how come it's available on every droplet? because though there is only one service running the port that we deployed it on is mapped for every droplet in the swarm so when we hit port 80 on swarm-1 which does not have the service running it immediately knows which application we are trying to use and forwards our request to that host.

11 . Now when we want to deploy multiple instances of this application as a container we will use below command to deploy those many replicas of the container in docker swarm :

docker service update --replicas 10 website

This will deploy 10 replicas of the container among the droplets in docker swarm.

12.Now try shutting down one of the droplets in docker swarm, you will observe that though the containers on that droplet are terminated, those containers were redeployed on other droplets in the docker swarm.

This increases the availability and scalability of our application in the production.

for installing latest vesrion on ubuntu

of app to be deployed inside containers in docker swarm environment.

GitHub Repository
Shellscript
Docker image