├── LICENSE ├── couchbase-cluster-swarm-mode.adoc ├── docker-compose-ddc.yml ├── docker-swarm-machine.sh ├── docker-ubuntu.adoc ├── drain-node.adoc ├── labels-constraints.adoc ├── readme.adoc ├── rolling-updates.adoc ├── second-manager.adoc ├── service-scale.adoc ├── swarm-mode-amazon.adoc ├── swarm-mode-amazon.sh ├── swarm-mode-machine-output.adoc └── swarm-mode-machine.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /couchbase-cluster-swarm-mode.adoc: -------------------------------------------------------------------------------- 1 | = Couchbase Cluster using Swarm Mode 2 | 3 | == Single Docker Engine 4 | 5 | . Configure a single Docker on AWS using link:docker-ubuntu.adoc[]. 6 | . Initialize Swarm mode: `docker swarm init` 7 | . Create an overlay network: `docker network create -d overlay couchbase` 8 | . Create a "`master`" service: `docker service create --name couchbase-master -p 8091:8091 --replicas 1 --network couchbase -e TYPE=MASTER arungupta/couchbase:swarm` 9 | . Create a "`worker`" service: `docker service create --name couchbase-worker --replicas 1 -e TYPE=WORKER -e COUCHBASE_MASTER=couchbase-master.couchbase --network couchbase arungupta/couchbase:swarm` 10 | . Optionally, rebalance the cluster 11 | 12 | == Docker for AWS 13 | 14 | . Create a cluster of Docker Engines with Swarm Mode using Docker for https://beta.docker.com/docs/deploy/[AWS Cloud Formation template] 15 | . Find `Master` in `Outputs` tab, get the public IP address of the master, ssh to it using `ssh -i docker@`. Exit out of the shell. 16 | . Create a SSH tunnel: `ssh -NL localhost:2374:/var/run/docker.sock docker@ &` 17 | . `export DOCKER_HOST=localhost:2374` 18 | . Create overlay network: `docker network create -d overlay couchbase` 19 | . Create "`master`" service: `docker service create --name couchbase-master -p 8091:8091 --replicas 1 --network couchbase -e TYPE=MASTER arungupta/couchbase:swarm` 20 | . Access Couchbase Web Console: http://:8091. Use `Administrator` and `password` credentials. 21 | . Create "`worker`" service: `docker service create --name couchbase-worker --replicas 1 -e TYPE=WORKER -e COUCHBASE_MASTER=couchbase-master.couchbase --network couchbase arungupta/couchbase:swarm` 22 | . Scale the "`worker`" service: `docker service scale couchbase-worker=3` 23 | 24 | 25 | -------------------------------------------------------------------------------- /docker-compose-ddc.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | couchbase-master: 4 | image: arungupta/couchbase:swarm 5 | ports: 6 | - 8091:8091 7 | environment: 8 | - TYPE=MASTER 9 | networks: 10 | default: 11 | driver: overlay 12 | -------------------------------------------------------------------------------- /docker-swarm-machine.sh: -------------------------------------------------------------------------------- 1 | # Docker Machine for Consul 2 | docker-machine \ 3 | create \ 4 | -d virtualbox \ 5 | consul-machine 6 | 7 | # Start Consul 8 | docker $(docker-machine config consul-machine) run -d --restart=always \ 9 | -p "8500:8500" \ 10 | -h "consul" \ 11 | progrium/consul -server -bootstrap 12 | 13 | # Docker Swarm master 14 | docker-machine \ 15 | create \ 16 | -d virtualbox \ 17 | --swarm \ 18 | --swarm-master \ 19 | --swarm-discovery="consul://$(docker-machine ip consul-machine):8500" \ 20 | --engine-opt="cluster-store=consul://$(docker-machine ip consul-machine):8500" \ 21 | --engine-opt="cluster-advertise=eth1:2376" \ 22 | swarm-master 23 | 24 | # Docker Swarm node-01 25 | docker-machine \ 26 | create \ 27 | -d virtualbox \ 28 | --swarm \ 29 | --swarm-discovery="consul://$(docker-machine ip consul-machine):8500" \ 30 | --engine-opt="cluster-store=consul://$(docker-machine ip consul-machine):8500" \ 31 | --engine-opt="cluster-advertise=eth1:2376" \ 32 | swarm-node-01 33 | 34 | # Docker Swarm node-02 35 | docker-machine \ 36 | create \ 37 | -d virtualbox \ 38 | --virtualbox-disk-size "5000" \ 39 | --swarm \ 40 | --swarm-discovery="consul://$(docker-machine ip consul-machine):8500" \ 41 | --engine-opt="cluster-store=consul://$(docker-machine ip consul-machine):8500" \ 42 | --engine-opt="cluster-advertise=eth1:2376" \ 43 | swarm-node-02 44 | 45 | # Configure to use Docker Swarm cluster 46 | eval "$(docker-machine env --swarm swarm-master)" 47 | 48 | -------------------------------------------------------------------------------- /docker-ubuntu.adoc: -------------------------------------------------------------------------------- 1 | = Setup Docker on Ubuntu Trusty 2 | 3 | Easiest way is explained at: https://get.docker.com/. 4 | 5 | Want to setup Docker on Ubuntu Trusty (14.04) using a script? 6 | 7 | Complete details at: https://docs.docker.com/engine/installation/linux/ubuntulinux/ 8 | 9 | Here is the quick script: 10 | 11 | ``` 12 | sudo apt-get update 13 | sudo apt-get install apt-transport-https ca-certificates 14 | sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D 15 | sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list' 16 | sudo apt-get update 17 | sudo apt-get purge lxc-docker 18 | apt-cache policy docker-engine 19 | sudo apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual 20 | sudo apt-get -y install docker-engine 21 | sudo usermod -aG docker $USER 22 | ``` 23 | -------------------------------------------------------------------------------- /drain-node.adoc: -------------------------------------------------------------------------------- 1 | = Drain Node 2 | 3 | This script shows how to _drain_ a node and bring it back to _active_ state. The _tasks_ on the node are distributed from active -> drain state but not vice versa. 4 | 5 | . Create a 3 node cluster using link:swarm-mode-amazon.adoc[]. Check the list of active nodes using `docker node ls`: 6 | + 7 | ``` 8 | ID HOSTNAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS 9 | 0yyap69qjg76ol5jbf811d5yz * ip-172-31-14-33 Accepted Ready Active Leader 10 | 4a8oodtjhg017dr0xxjm2cpr4 ip-172-31-14-35 Accepted Ready Active 11 | 70xqobszyfxsh6ussr38he6f5 ip-172-31-14-34 Accepted Ready Active 12 | ``` 13 | + 14 | It shows all nodes are active with one leader. 15 | + 16 | . Run 6 replicas of a service using `docker service create --name wildfly --replicas 6 jboss/wildfly` 17 | . Check the list of services using `docker service ls`: 18 | + 19 | ``` 20 | ID NAME REPLICAS IMAGE COMMAND 21 | 1n7h5v6kv3uy wildfly 6/6 jboss/wildfly 22 | ``` 23 | + 24 | . Check the list of tasks using `docker service tasks wildfly`: 25 | + 26 | ``` 27 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 28 | a2bxufy7l9su1sso77fkga7s8 wildfly.1 wildfly jboss/wildfly Running about a minute ago Running ip-172-31-14-35 29 | c26tsffz3n4u5r8qbo3wrpo03 wildfly.2 wildfly jboss/wildfly Running about a minute ago Running ip-172-31-14-33 30 | 4xb25mk785hxn9pd9sfykrwdp wildfly.3 wildfly jboss/wildfly Running about a minute ago Running ip-172-31-14-34 31 | 3wm9txt61ornc3abfna5tv84i wildfly.4 wildfly jboss/wildfly Running about a minute ago Running ip-172-31-14-34 32 | by6o0bhaxe2gwu3dl8rwkn6b2 wildfly.5 wildfly jboss/wildfly Running about a minute ago Running ip-172-31-14-35 33 | eoe02mo3alc3dzklux5fqkp7r wildfly.6 wildfly jboss/wildfly Running about a minute ago Running ip-172-31-14-33 34 | ``` 35 | + 36 | Containers are evenly distributed across all the nodes. This is because of the default `spread` strategy. 37 | + 38 | . Drain a node `docker node update --availability drain ip-172-31-14-35` 39 | + 40 | . Check the list of nodes using `docker node ls`: 41 | + 42 | ``` 43 | ID HOSTNAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS 44 | 0yyap69qjg76ol5jbf811d5yz * ip-172-31-14-33 Accepted Ready Active Leader 45 | 4a8oodtjhg017dr0xxjm2cpr4 ip-172-31-14-35 Accepted Ready Drain 46 | 70xqobszyfxsh6ussr38he6f5 ip-172-31-14-34 Accepted Ready Active 47 | ``` 48 | + 49 | The node's status is changed accordinly. 50 | + 51 | . Check the list of services again using `docker service ls`: 52 | + 53 | ``` 54 | ID NAME REPLICAS IMAGE COMMAND 55 | 1n7h5v6kv3uy wildfly 6/6 jboss/wildfly 56 | ``` 57 | + 58 | . Check the list of tasks using `docker service tasks wildfly`: 59 | + 60 | ``` 61 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 62 | 4uvbvmz9v2262u89xu9e2zf8e wildfly.1 wildfly jboss/wildfly Running 49 seconds ago Running ip-172-31-14-33 63 | c26tsffz3n4u5r8qbo3wrpo03 wildfly.2 wildfly jboss/wildfly Running 3 minutes ago Running ip-172-31-14-33 64 | 4xb25mk785hxn9pd9sfykrwdp wildfly.3 wildfly jboss/wildfly Running 3 minutes ago Running ip-172-31-14-34 65 | 3wm9txt61ornc3abfna5tv84i wildfly.4 wildfly jboss/wildfly Running 3 minutes ago Running ip-172-31-14-34 66 | 914evxt319vbpc031pvo9yxd1 wildfly.5 wildfly jboss/wildfly Running 49 seconds ago Running ip-172-31-14-34 67 | eoe02mo3alc3dzklux5fqkp7r wildfly.6 wildfly jboss/wildfly Running 3 minutes ago Running ip-172-31-14-33 68 | ``` 69 | + 70 | Now the containers are distributed across two active nodes. 71 | + 72 | . Make the node active again using `docker node update --availability active ip-172-31-14-35`. 73 | . Check the list of nodes using `docker node ls`: 74 | + 75 | ``` 76 | ID HOSTNAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS 77 | 0yyap69qjg76ol5jbf811d5yz * ip-172-31-14-33 Accepted Ready Active Leader 78 | 4a8oodtjhg017dr0xxjm2cpr4 ip-172-31-14-35 Accepted Ready Active 79 | 70xqobszyfxsh6ussr38he6f5 ip-172-31-14-34 Accepted Ready Active 80 | ``` 81 | + 82 | . Check the list of tasks using `docker service tasks wildfly`: 83 | + 84 | ``` 85 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 86 | 4uvbvmz9v2262u89xu9e2zf8e wildfly.1 wildfly jboss/wildfly Running 2 minutes ago Running ip-172-31-14-33 87 | c26tsffz3n4u5r8qbo3wrpo03 wildfly.2 wildfly jboss/wildfly Running 5 minutes ago Running ip-172-31-14-33 88 | 4xb25mk785hxn9pd9sfykrwdp wildfly.3 wildfly jboss/wildfly Running 5 minutes ago Running ip-172-31-14-34 89 | 3wm9txt61ornc3abfna5tv84i wildfly.4 wildfly jboss/wildfly Running 5 minutes ago Running ip-172-31-14-34 90 | 914evxt319vbpc031pvo9yxd1 wildfly.5 wildfly jboss/wildfly Running 2 minutes ago Running ip-172-31-14-34 91 | eoe02mo3alc3dzklux5fqkp7r wildfly.6 wildfly jboss/wildfly Running 5 minutes ago Running ip-172-31-14-33 92 | ``` 93 | + 94 | The tasks are not redistributed again. 95 | 96 | -------------------------------------------------------------------------------- /labels-constraints.adoc: -------------------------------------------------------------------------------- 1 | = Assign Labels to Docker Daemon and Constraints on Containers 2 | 3 | This script can be used to assign _labels_ to Docker daemon. These labels are then later used to run containers with specific _constraints_. 4 | 5 | . Assign label to Docker daemon on node with ``: 6 | + 7 | ``` 8 | sudo sed -i '/#DOCKER_OPTS/c\DOCKER_OPTS="--label=couchbase.mds=index"' /etc/default/docker 9 | sudo restart docker 10 | docker info 11 | ``` 12 | + 13 | . Run containers with a constraint: 14 | + 15 | ``` 16 | docker service create --name=cb-mds-index --constraint engine.labels.couchbase.mds==index couchbase 17 | ``` 18 | 19 | -------------------------------------------------------------------------------- /readme.adoc: -------------------------------------------------------------------------------- 1 | = Docker Scripts 2 | 3 | This repo have scripts that can be used to build, ship and run Docker in different environments. 4 | 5 | -------------------------------------------------------------------------------- /rolling-updates.adoc: -------------------------------------------------------------------------------- 1 | = Rolling Updates 2 | 3 | Show rolling update of 6 services from `arungupta/wildfly-app:1` to `arungupta/wildfly-app:2`. 4 | 5 | . Create a service with 6 replicas: `docker service create --name wildfly-app --replicas 6 -p 8080:8080 arungupta/wildfly-app:1` 6 | . Check service using `docker service ls` 7 | + 8 | ``` 9 | ID NAME REPLICAS IMAGE COMMAND 10 | 3dsliqsjh5y2 wildfly-app 6/6 arungupta/wildfly-app:1 11 | ``` 12 | + 13 | All services are using `arungupta/wildfly-app:1`. 14 | + 15 | . Check tasks using `docker service tasks wildfly-app`: 16 | + 17 | ``` 18 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 19 | 24ioasmtd1g0no655qesnnagc wildfly-app.1 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 20 | 1roqbjk8h1z46nuupb81wgjar wildfly-app.2 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 21 | dc06t7xl4k2vxnucx1vlzc3s3 wildfly-app.3 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 22 | dkyd7ypzfl25vycaorg2h0car wildfly-app.4 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 23 | a8yjgud48j2zb3na533lseujp wildfly-app.5 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 24 | 9h0h1i7tpusciwgzqi565gzai wildfly-app.6 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 25 | ``` 26 | + 27 | All tasks are using `arungupta/wildfly-app:1`. 28 | + 29 | . Update our service by replacing 2 tasks at a time, every 10 seconds: `docker service update wildfly-app --image arungupta/wildfly-app:2 --update-parallelism 2 --update-delay 10s`. 30 | + 31 | .. First update: 32 | + 33 | ``` 34 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 35 | er8tbrsay13g9g6mt9animl8t wildfly-app.1 wildfly-app arungupta/wildfly-app:2 Starting 2 hours ago Running moby 36 | ezuugmg4nnxohpzcng47ifi8a wildfly-app.2 wildfly-app arungupta/wildfly-app:2 Ready 2 hours ago Running moby 37 | dc06t7xl4k2vxnucx1vlzc3s3 wildfly-app.3 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 38 | dkyd7ypzfl25vycaorg2h0car wildfly-app.4 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 39 | a8yjgud48j2zb3na533lseujp wildfly-app.5 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 40 | 9h0h1i7tpusciwgzqi565gzai wildfly-app.6 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 41 | ``` 42 | + 43 | Two containers are updated to `arungupta/wildfly-app:2`. 44 | + 45 | .. After ~10 secs: 46 | + 47 | ``` 48 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 49 | er8tbrsay13g9g6mt9animl8t wildfly-app.1 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 50 | ezuugmg4nnxohpzcng47ifi8a wildfly-app.2 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 51 | dc06t7xl4k2vxnucx1vlzc3s3 wildfly-app.3 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 52 | dkyd7ypzfl25vycaorg2h0car wildfly-app.4 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 53 | ``` 54 | + 55 | Two more containers running `arungupta/wildlfy-app:1` are terminated. 56 | + 57 | . New version of the container `arungupta/wildfly-app:2` are launched: 58 | + 59 | ``` 60 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 61 | er8tbrsay13g9g6mt9animl8t wildfly-app.1 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 62 | ezuugmg4nnxohpzcng47ifi8a wildfly-app.2 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 63 | dc06t7xl4k2vxnucx1vlzc3s3 wildfly-app.3 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 64 | dkyd7ypzfl25vycaorg2h0car wildfly-app.4 wildfly-app arungupta/wildfly-app:1 Running 2 hours ago Running moby 65 | 4ss8mghk1z7kmvvdtvbbvrbmc wildfly-app.5 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 66 | awyb7air1qth6s2i4itamsi5l wildfly-app.6 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 67 | ``` 68 | + 69 | Now four containers with the version `arungupta/wildfly-app:2` are available. 70 | + 71 | .. After ~10 secs: 72 | + 73 | ``` 74 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 75 | er8tbrsay13g9g6mt9animl8t wildfly-app.1 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 76 | ezuugmg4nnxohpzcng47ifi8a wildfly-app.2 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 77 | 4ss8mghk1z7kmvvdtvbbvrbmc wildfly-app.5 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 78 | awyb7air1qth6s2i4itamsi5l wildfly-app.6 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 79 | ``` 80 | + 81 | All containers running `arungupta/wildfly-app:1` are terminated. 82 | + 83 | .. Last two containers `arungupta/wildfly-app:2` are launched: 84 | + 85 | ``` 86 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 87 | er8tbrsay13g9g6mt9animl8t wildfly-app.1 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 88 | ezuugmg4nnxohpzcng47ifi8a wildfly-app.2 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 89 | 35qnoheuinyw9ti0m0mopigbv wildfly-app.3 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 90 | blhbhuxuy5psqjupig6sie7o5 wildfly-app.4 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 91 | 4ss8mghk1z7kmvvdtvbbvrbmc wildfly-app.5 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 92 | awyb7air1qth6s2i4itamsi5l wildfly-app.6 wildfly-app arungupta/wildfly-app:2 Running 2 hours ago Running moby 93 | ``` 94 | + 95 | . Check service using `docker service ls`: 96 | + 97 | ``` 98 | ID NAME REPLICAS IMAGE COMMAND 99 | 3dsliqsjh5y2 wildfly-app 6/6 arungupta/wildfly-app:2 100 | ``` 101 | + 102 | All services are now using `arungupta/wildfly-app:1`. 103 | 104 | -------------------------------------------------------------------------------- /second-manager.adoc: -------------------------------------------------------------------------------- 1 | = Drain Node 2 | 3 | This script shows how to add a second manager to the cluster. 4 | 5 | . Start 4 Amazon instances: `aws ec2 run-instances --image-id ami-06116566 --count 4 --instance-type t2.micro --key-name arun@couchbase --security-groups swarm-mode` 6 | . Create a 3 node Swarm cluster using link:swarm-mode-amazon.adoc[]. Check the list of active nodes using `docker node ls`: 7 | + 8 | ``` 9 | ID HOSTNAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS 10 | 0yyap69qjg76ol5jbf811d5yz * ip-172-31-14-33 Accepted Ready Active Leader 11 | 4a8oodtjhg017dr0xxjm2cpr4 ip-172-31-14-35 Accepted Ready Active 12 | 70xqobszyfxsh6ussr38he6f5 ip-172-31-14-34 Accepted Ready Active 13 | ``` 14 | + 15 | It shows all nodes are active with one leader. 16 | + 17 | . Add 4th node as manager: 18 | + 19 | ``` 20 | ssh -o StrictHostKeyChecking=no -i /Users/arungupta/.ssh/aruncouchbase.pem ubuntu@ "docker swarm join --manager --secret mySecret --listen-addr :2377 :2377" 21 | ``` 22 | + 23 | This shows: 24 | + 25 | ``` 26 | Error response from daemon: Your node is in the process of joining the cluster but needs to be accepted by existing cluster member. 27 | To accept this node into cluster run "docker node accept duiwczeimfrznk9ab7gyi0lfm" in an existing cluster manager. Use "docker info" command to see the current Swarm status of your node. 28 | ``` 29 | + 30 | . Check nodes using `docker node ls`: 31 | + 32 | ``` 33 | ID HOSTNAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS 34 | 2xftpki6053v3esg1uh9116hu ip-172-31-1-44 Accepted Ready Active 35 | 47x45mx43erudzz6lq4xkzmbc * ip-172-31-1-43 Accepted Ready Active Leader 36 | d16tvcy99yo8ucqfgckegtzx6 ip-172-31-1-41 Accepted Ready Active 37 | duiwczeimfrznk9ab7gyi0lfm Pending Unknown Active 38 | ``` 39 | + 40 | . Accept the node using `master1`: `docker node accept duiwczeimfrznk9ab7gyi0lfm`. Alternatively, udpate existing Swarm manager to auto-accept new managers as `docker update swarm --auto-accept manager`. 41 | . Check nodes again using `docker node ls`: 42 | + 43 | ``` 44 | ID HOSTNAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS 45 | 2xftpki6053v3esg1uh9116hu ip-172-31-1-44 Accepted Ready Active 46 | 47x45mx43erudzz6lq4xkzmbc * ip-172-31-1-43 Accepted Ready Active Leader 47 | d16tvcy99yo8ucqfgckegtzx6 ip-172-31-1-41 Accepted Ready Active 48 | duiwczeimfrznk9ab7gyi0lfm ip-172-31-1-42 Accepted Ready Active Reachable 49 | ``` 50 | 51 | -------------------------------------------------------------------------------- /service-scale.adoc: -------------------------------------------------------------------------------- 1 | = Scale service and check tasks 2 | 3 | . Start a service: 4 | 5 | docker service create --name wildfly -p 8080:8080 jboss/wildfly 6 | 7 | . Check service using `docker service ls`: 8 | + 9 | ``` 10 | ID NAME REPLICAS IMAGE COMMAND 11 | 9q80x48peoax wildfly 1/1 jboss/wildfly 12 | ``` 13 | + 14 | . Check tasks in service using `docker service tasks wildfly`: 15 | + 16 | ``` 17 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 18 | 1i8negn36baptrk8go7v3bfz4 wildfly.1 wildfly jboss/wildfly Running 59 seconds ago Running ip-172-31-8-7 19 | ``` 20 | + 21 | . Scale service to 6 replicas: 22 | 23 | docker service scale wildfly=6 24 | 25 | . Check service using `docker service ls`: 26 | + 27 | ``` 28 | ID NAME REPLICAS IMAGE COMMAND 29 | 9q80x48peoax wildfly 6/6 jboss/wildfly 30 | ``` 31 | + 32 | . Check tasks using `docker service tasks wildfly`: 33 | + 34 | ``` 35 | ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 36 | 1i8negn36baptrk8go7v3bfz4 wildfly.1 wildfly jboss/wildfly Running 2 minutes ago Running ip-172-31-8-7 37 | 1d1ahuqh59z4mliimxp91xltn wildfly.2 wildfly jboss/wildfly Running 48 seconds ago Running ip-172-31-8-5 38 | 7jt9h14iczkkp0zpnmvqueomo wildfly.3 wildfly jboss/wildfly Running 48 seconds ago Running ip-172-31-8-5 39 | 6m732ikg0a6wp0phufa53dct2 wildfly.4 wildfly jboss/wildfly Running 48 seconds ago Running ip-172-31-8-7 40 | c3ilztztbx1ogpo5x8558scwl wildfly.5 wildfly jboss/wildfly Running 48 seconds ago Running ip-172-31-8-6 41 | ep8bih5ivwfs8akldg3xy0bqe wildfly.6 wildfly jboss/wildfly Running 48 seconds ago Running ip-172-31-8-6 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /swarm-mode-amazon.adoc: -------------------------------------------------------------------------------- 1 | = Docker Swarm Mode Cluster on Amazon 2 | 3 | This script will create a 3-node (1 manager, 2 worker) Swarm Mode cluster on Amazon. 4 | 5 | == Required 6 | 7 | . Amazon account 8 | . Docker 1.12 RC4+ 9 | 10 | == Script 11 | 12 | === Start Ubuntu instance 13 | 14 | `aws ec2 run-instances --image-id ami-06116566 --count 3 --instance-type t2.micro --key-name arun@couchbase --security-groups swarm-mode` 15 | 16 | === Install experimental Docker 17 | 18 | ``` 19 | publicIp=`aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].PublicDnsName` 20 | privateIp=`aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].PrivateDnsName` 21 | for node in $publicIp 22 | do 23 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@$node 'curl -fsSL https://experimental.docker.com/ | sh' 24 | ssh -i ~/.ssh/aruncouchbase.pem ubuntu@$node 'sudo usermod -aG docker ubuntu' 25 | ssh -i ~/.ssh/aruncouchbase.pem ubuntu@$node 'docker version' 26 | done 27 | ``` 28 | 29 | === Setup Swarm mode 30 | 31 | ``` 32 | publicIpList=`aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].PublicDnsName` 33 | privateIpList=`aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].PrivateDnsName` 34 | 35 | publicIp=($publicIpList) 36 | privateIp=($privateIpList) 37 | 38 | #Setup Swarm manager 39 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[0]} "docker swarm init --listen-addr ${privateIp[0]}:2377 --secret mySecret" 40 | 41 | #Setup Swarm worker 42 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[1]} "docker swarm join --secret mySecret ${privateIp[0]}:2377" 43 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[2]} "docker swarm join --secret mySecret ${privateIp[0]}:2377" 44 | 45 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[0]} "docker node ls" 46 | ``` 47 | === Terminate instances 48 | 49 | `aws ec2 terminate-instances --instance-ids `aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].InstanceId`` 50 | 51 | -------------------------------------------------------------------------------- /swarm-mode-amazon.sh: -------------------------------------------------------------------------------- 1 | set -x 2 | 3 | # Start three Ubuntu instances 4 | #aws ec2 run-instances --image-id ami-06116566 --count 3 --instance-type t2.micro --key-name arun@couchbase --security-groups swarm-mode 5 | 6 | # Get all public and private IP addresses 7 | publicIpList=`aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].PublicDnsName` 8 | privateIpList=`aws ec2 describe-instances --filters Name=instance-state-name,Values=running | jq -r .Reservations[].Instances[].PrivateDnsName` 9 | 10 | # Install experimental Docker 11 | for node in $publicIpList 12 | do 13 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@$node 'curl -fsSL https://experimental.docker.com/ | sh' 14 | ssh -i ~/.ssh/aruncouchbase.pem ubuntu@$node 'sudo usermod -aG docker ubuntu' 15 | ssh -i ~/.ssh/aruncouchbase.pem ubuntu@$node 'docker version' 16 | done 17 | set -x 18 | 19 | # Convert IP addresses into an array 20 | publicIp=($publicIpList) 21 | privateIp=($privateIpList) 22 | 23 | #Setup Swarm manager 24 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[0]} "docker swarm init --listen-addr ${privateIp[0]}:2377 --secret mySecret" 25 | 26 | #Setup Swarm worker 27 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[1]} "docker swarm join --secret mySecret ${privateIp[0]}:2377" 28 | ssh -o StrictHostKeyChecking=no -i ~/.ssh/aruncouchbase.pem ubuntu@${publicIp[2]} "docker swarm join --secret mySecret ${privateIp[0]}:2377" 29 | 30 | -------------------------------------------------------------------------------- /swarm-mode-machine-output.adoc: -------------------------------------------------------------------------------- 1 | = 3 Manager and 3 Worker Docker Swarm Cluster on Machine Output 2 | 3 | ``` 4 | ======> Creating 3 manager machines ... 5 | ======> Creating manager1 machine ... 6 | Running pre-create checks... 7 | Creating machine... 8 | (manager1) Copying /Users/arungupta/.docker/machine/cache/boot2docker.iso to /Users/arungupta/.docker/machine/machines/manager1/boot2docker.iso... 9 | (manager1) Creating VirtualBox VM... 10 | (manager1) Creating SSH key... 11 | (manager1) Starting the VM... 12 | (manager1) Check network to re-create if needed... 13 | (manager1) Waiting for an IP... 14 | Waiting for machine to be running, this may take a few minutes... 15 | Detecting operating system of created instance... 16 | Waiting for SSH to be available... 17 | Detecting the provisioner... 18 | Provisioning with boot2docker... 19 | Copying certs to the local machine directory... 20 | Copying certs to the remote machine... 21 | Setting Docker configuration on the remote daemon... 22 | Checking connection to Docker... 23 | Docker is up and running! 24 | To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env manager1 25 | ======> Creating manager2 machine ... 26 | Running pre-create checks... 27 | Creating machine... 28 | (manager2) Copying /Users/arungupta/.docker/machine/cache/boot2docker.iso to /Users/arungupta/.docker/machine/machines/manager2/boot2docker.iso... 29 | (manager2) Creating VirtualBox VM... 30 | (manager2) Creating SSH key... 31 | (manager2) Starting the VM... 32 | (manager2) Check network to re-create if needed... 33 | (manager2) Waiting for an IP... 34 | Waiting for machine to be running, this may take a few minutes... 35 | Detecting operating system of created instance... 36 | Waiting for SSH to be available... 37 | Detecting the provisioner... 38 | Provisioning with boot2docker... 39 | Copying certs to the local machine directory... 40 | Copying certs to the remote machine... 41 | Setting Docker configuration on the remote daemon... 42 | Checking connection to Docker... 43 | Docker is up and running! 44 | To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env manager2 45 | ======> Creating manager3 machine ... 46 | Running pre-create checks... 47 | Creating machine... 48 | (manager3) Copying /Users/arungupta/.docker/machine/cache/boot2docker.iso to /Users/arungupta/.docker/machine/machines/manager3/boot2docker.iso... 49 | (manager3) Creating VirtualBox VM... 50 | (manager3) Creating SSH key... 51 | (manager3) Starting the VM... 52 | (manager3) Check network to re-create if needed... 53 | (manager3) Waiting for an IP... 54 | Waiting for machine to be running, this may take a few minutes... 55 | Detecting operating system of created instance... 56 | Waiting for SSH to be available... 57 | Detecting the provisioner... 58 | Provisioning with boot2docker... 59 | Copying certs to the local machine directory... 60 | Copying certs to the remote machine... 61 | Setting Docker configuration on the remote daemon... 62 | Checking connection to Docker... 63 | Docker is up and running! 64 | To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env manager3 65 | ======> Creating 3 worker machines ... 66 | ======> Creating worker1 machine ... 67 | Running pre-create checks... 68 | Creating machine... 69 | (worker1) Copying /Users/arungupta/.docker/machine/cache/boot2docker.iso to /Users/arungupta/.docker/machine/machines/worker1/boot2docker.iso... 70 | (worker1) Creating VirtualBox VM... 71 | (worker1) Creating SSH key... 72 | (worker1) Starting the VM... 73 | (worker1) Check network to re-create if needed... 74 | (worker1) Waiting for an IP... 75 | Waiting for machine to be running, this may take a few minutes... 76 | Detecting operating system of created instance... 77 | Waiting for SSH to be available... 78 | Detecting the provisioner... 79 | Provisioning with boot2docker... 80 | Copying certs to the local machine directory... 81 | Copying certs to the remote machine... 82 | Setting Docker configuration on the remote daemon... 83 | Checking connection to Docker... 84 | Docker is up and running! 85 | To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env worker1 86 | ======> Creating worker2 machine ... 87 | Running pre-create checks... 88 | Creating machine... 89 | (worker2) Copying /Users/arungupta/.docker/machine/cache/boot2docker.iso to /Users/arungupta/.docker/machine/machines/worker2/boot2docker.iso... 90 | (worker2) Creating VirtualBox VM... 91 | (worker2) Creating SSH key... 92 | (worker2) Starting the VM... 93 | (worker2) Check network to re-create if needed... 94 | (worker2) Waiting for an IP... 95 | Waiting for machine to be running, this may take a few minutes... 96 | Detecting operating system of created instance... 97 | Waiting for SSH to be available... 98 | Detecting the provisioner... 99 | Provisioning with boot2docker... 100 | Copying certs to the local machine directory... 101 | Copying certs to the remote machine... 102 | Setting Docker configuration on the remote daemon... 103 | Checking connection to Docker... 104 | Docker is up and running! 105 | To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env worker2 106 | ======> Creating worker3 machine ... 107 | Running pre-create checks... 108 | Creating machine... 109 | (worker3) Copying /Users/arungupta/.docker/machine/cache/boot2docker.iso to /Users/arungupta/.docker/machine/machines/worker3/boot2docker.iso... 110 | (worker3) Creating VirtualBox VM... 111 | (worker3) Creating SSH key... 112 | (worker3) Starting the VM... 113 | (worker3) Check network to re-create if needed... 114 | (worker3) Waiting for an IP... 115 | Waiting for machine to be running, this may take a few minutes... 116 | Detecting operating system of created instance... 117 | Waiting for SSH to be available... 118 | Detecting the provisioner... 119 | Provisioning with boot2docker... 120 | Copying certs to the local machine directory... 121 | Copying certs to the remote machine... 122 | Setting Docker configuration on the remote daemon... 123 | Checking connection to Docker... 124 | Docker is up and running! 125 | To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env worker3 126 | NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS 127 | manager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0 128 | manager2 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0 129 | manager3 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0 130 | worker1 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0 131 | worker2 - virtualbox Running tcp://192.168.99.104:2376 v1.12.0 132 | worker3 - virtualbox Running tcp://192.168.99.105:2376 v1.12.0 133 | ======> Initializing first swarm manager ... 134 | Swarm initialized: current node (awaxcheomhagl7engrut9rha3) is now a manager. 135 | 136 | To add a worker to this swarm, run the following command: 137 | docker swarm join \ 138 | --token SWMTKN-1-5x04iqjfl58nu9ap7mmzh9oqp5qqcy7zggojy8n9pefmudnnhx-28pdn4x4btrz4tzfn6cqcw7md \ 139 | 192.168.99.100:2377 140 | 141 | To add a manager to this swarm, run the following command: 142 | docker swarm join \ 143 | --token SWMTKN-1-5x04iqjfl58nu9ap7mmzh9oqp5qqcy7zggojy8n9pefmudnnhx-7iuzrysqktro6eky9r1nx8unq \ 144 | 192.168.99.100:2377 145 | manager_token: SWMTKN-1-5x04iqjfl58nu9ap7mmzh9oqp5qqcy7zggojy8n9pefmudnnhx-7iuzrysqktro6eky9r1nx8unq 146 | worker_token: SWMTKN-1-5x04iqjfl58nu9ap7mmzh9oqp5qqcy7zggojy8n9pefmudnnhx-28pdn4x4btrz4tzfn6cqcw7md 147 | ======> manager2 joining swarm as manager ... 148 | This node joined a swarm as a manager. 149 | ======> manager3 joining swarm as manager ... 150 | This node joined a swarm as a manager. 151 | ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 152 | 2tcpb0nvk4jrrot75zyumf35f manager2 Ready Active Reachable 153 | awaxcheomhagl7engrut9rha3 * manager1 Ready Active Leader 154 | djq7vrb7rl4zlz3qbluhrj2by manager3 Ready Active Reachable 155 | ======> worker1 joining swarm as worker ... 156 | This node joined a swarm as a worker. 157 | ======> worker2 joining swarm as worker ... 158 | This node joined a swarm as a worker. 159 | ======> worker3 joining swarm as worker ... 160 | This node joined a swarm as a worker. 161 | ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 162 | 2tcpb0nvk4jrrot75zyumf35f manager2 Ready Active Reachable 163 | 8vy743bwfmhtdo8tt3cnvl9ye worker3 Ready Active 164 | awaxcheomhagl7engrut9rha3 * manager1 Ready Active Leader 165 | djq7vrb7rl4zlz3qbluhrj2by manager3 Ready Active Reachable 166 | e57cfmfydncrh5sej6eh8old8 worker2 Ready Active 167 | evmnq65tt9f3fthryccmz1a9e worker1 Ready Active 168 | ``` 169 | -------------------------------------------------------------------------------- /swarm-mode-machine.sh: -------------------------------------------------------------------------------- 1 | # Swarm mode using Docker Machine 2 | 3 | managers=3 4 | workers=3 5 | 6 | # create manager machines 7 | echo "======> Creating $managers manager machines ..."; 8 | for node in $(seq 1 $managers); 9 | do 10 | echo "======> Creating manager$node machine ..."; 11 | docker-machine create -d virtualbox manager$node; 12 | done 13 | 14 | # create worker machines 15 | echo "======> Creating $workers worker machines ..."; 16 | for node in $(seq 1 $workers); 17 | do 18 | echo "======> Creating worker$node machine ..."; 19 | docker-machine create -d virtualbox worker$node; 20 | done 21 | 22 | # list all machines 23 | docker-machine ls 24 | 25 | # initialize swarm mode and create a manager 26 | echo "======> Initializing first swarm manager ..." 27 | docker-machine ssh manager1 "docker swarm init --listen-addr $(docker-machine ip manager1) --advertise-addr $(docker-machine ip manager1)" 28 | 29 | # get manager and worker tokens 30 | export manager_token=`docker-machine ssh manager1 "docker swarm join-token manager -q"` 31 | export worker_token=`docker-machine ssh manager1 "docker swarm join-token worker -q"` 32 | 33 | echo "manager_token: $manager_token" 34 | echo "worker_token: $worker_token" 35 | 36 | # other masters join swarm 37 | for node in $(seq 2 $managers); 38 | do 39 | echo "======> manager$node joining swarm as manager ..." 40 | docker-machine ssh manager$node \ 41 | "docker swarm join \ 42 | --token $manager_token \ 43 | --listen-addr $(docker-machine ip manager$node) \ 44 | --advertise-addr $(docker-machine ip manager$node) \ 45 | $(docker-machine ip manager1)" 46 | done 47 | 48 | # show members of swarm 49 | docker-machine ssh manager1 "docker node ls" 50 | 51 | # workers join swarm 52 | for node in $(seq 1 $workers); 53 | do 54 | echo "======> worker$node joining swarm as worker ..." 55 | docker-machine ssh worker$node \ 56 | "docker swarm join \ 57 | --token $worker_token \ 58 | --listen-addr $(docker-machine ip worker$node) \ 59 | --advertise-addr $(docker-machine ip worker$node) \ 60 | $(docker-machine ip manager1):2377" 61 | done 62 | 63 | # show members of swarm 64 | docker-machine ssh manager1 "docker node ls" 65 | 66 | # Cleanup 67 | # # Stop machines 68 | # docker-machine stop worker1 worker2 worker3 manager1 manager2 manager3 69 | 70 | # # remove machines 71 | # docker-machine rm worker1 worker2 worker3 manager1 manager2 manager3 72 | --------------------------------------------------------------------------------