Getting Started with Docker (MAC Environment)-Part 4 swarms

Source: Internet
Author: User
Tags docker swarm

Part-4 Swarms Introduction

This section is mainly about how to deploy Docker applications in cluster mode; The concept of clustering is well understood, and multiple machines work together to accomplish a task; like Hadoop's clusters, Docker is the equivalent of a management machine, with some workers Docker clusters are also deployed in similar ways.

Machine required to create the cluster

The so-called cluster, is certainly a number of machines, in order to achieve the effect of the local cluster, only with virtual machines, referring to the virtual machine, you can use VirtualBox to create a virtual machine, but do not need to install VirtualBox after the mouse created XX virtual machine, using Docker commands, It can be created with VirtualBox as the driver, and the process is roughly as follows:

    • Create 2 virtual machines
docker-machine create --driver virtualbox myvm1docker-machine create --driver virtualbox myvm2
    • Use docker-machine ls to view a list of virtual machines, with the following effects
? docker-machine lsNAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORSmyvm1   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.05.0-cemyvm2   -        virtualbox   Running   tcp://192.168.99.101:2376           v18.05.0-ce
Initializing swarm, adding nodes

Once the machine has been created, you can create a cluster with the following general steps:

    • Set one of the management machines first (leader)
? docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.100"Swarm initialized: current node (erobf751l09mmidt60y8idg6i) is now a manager.To add a worker to this swarm, run the following command:    docker swarm join --token SWMTKN-1-5shucnjzwdjwyzpquec8k8obvauasnvlc7g81da84ucv6y6um5-crfqd1by0v3693jov5u24jf40 192.168.99.100:2377To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
    • Set another machine as a worker, as indicated above
? docker-machine ssh myvm2 "docker swarm join --token SWMTKN-1-5shucnjzwdjwyzpquec8k8obvauasnvlc7g81da84ucv6y6um5-crfqd1by0v3693jov5u24jf40 192.168.99.100:2377"This node joined a swarm as a worker.
    • To view the status of the cluster, log on to the management machine to view
? docker-machine ssh myvm1 "docker node ls"ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSIONerobf751l09mmidt60y8idg6i *   myvm1               Ready               Active              Leader              18.05.0-cet7dioehz2db7wcs6lz4gzcg2y     myvm2               Ready               Active                                  18.05.0-ce
    • If you want to get the machine out of the cluster, usedocker-machi ssh myvm2 "docker swarm leave"
Deploying Docker application configuration on a cluster docker-machine env

Before the way to talk with vm1/vm2 more trouble, now can be through docker-machine env <machine> direct communication, and docker-machine ssh the difference is: the former can use the local docker-compose.yml files to configure the cluster, instead of copying the files in the past. The general approach is as follows:

? docker-machine env myvm1export DOCKER_TLS_VERIFY="1"export DOCKER_HOST="tcp://192.168.99.100:2376"export DOCKER_CERT_PATH="/Users/wang/.docker/machine/machines/myvm1"export DOCKER_MACHINE_NAME="myvm1"# Run this command to configure your shell:# eval $(docker-machine env myvm1)? eval $(docker-machine env myvm1)? docker-machine lsNAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORSmyvm1   *        virtualbox   Running   tcp://192.168.99.100:2376           v18.05.0-cemyvm2   -        virtualbox   Running   tcp://192.168.99.101:2376           v18.05.0-ce
Deploying apps on the Swarm management machine
    • By using the previous step, you can actually control the MYVM1, and then you can deploy the app in the following way:
? docker stack deploy -c docker-compose.yml getstartedlabCreating network getstartedlab_webnetCreating service getstartedlab_web
    • You can docker stack ps xxx check to see if the startup was successful, as follows:
 ?                Docker_file Docker stack PS getstartedlab zi9r49lihpf0 getstartedlab_web.1 btchild/get-started:part-2 myvm2 Running Preparing about a minute agovc3z9spbwjhk getstartedlab_web.2 btchild/get-s Tarted:part-2 myvm2 Running Preparing about a minute agos2fuh8z5leto getstartedlab_web.        3 btchild/get-started:part-2 myvm1 Running Running about a minute agonhd3cpud5k28 getstartedlab_web.4 btchild/get-started:part-2 myvm1 Running Running seconds AGON3TC R1k8ieen getstartedlab_web.5 btchild/get-started:part-2 myvm1 Running Running Abo UT a minute ago  
    • Http://192.168.99.100:4000/can then be accessed through the browser to see the results, or can be viewed through the http://192.168.99.101:4000/, equivalent to achieve the effect of load balancing, but also to achieve the operation of the cluster
    • In addition, copies can be docker-machine scp file_name machine_name achieved by
    • Deactivate an app
?  docker_file docker stack rm getstartedlabRemoving service getstartedlab_webRemoving network getstartedlab_webnet
    • Leave Swarm's management machine
?  docker_file eval $(docker-machine env -u)
Restart VM
    • You can docker-machine stop myvm1 deactivate a virtual machine by
    • docker-machine start myvm1to enable a virtual machine by

Getting Started with Docker (MAC Environment)-Part 4 swarms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.