From 1a23b04d277781b4ced3a77620179882965450af Mon Sep 17 00:00:00 2001 From: Mano Marks Date: Thu, 22 Sep 2016 13:05:19 -0700 Subject: [PATCH 1/4] updating begginer tutorial for Docker for Windows. Updating example voting app to represent .NET worker. Some cleanup --- beginner/chapters/setup.md | 6 +++++- beginner/chapters/votingapp.md | 16 +++++++--------- beginner/chapters/webapps.md | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/beginner/chapters/setup.md b/beginner/chapters/setup.md index eb5c763075..170884deb5 100644 --- a/beginner/chapters/setup.md +++ b/beginner/chapters/setup.md @@ -6,10 +6,14 @@ There are no specific skills needed for this tutorial beyond a basic comfort wit ### Setting up your computer Getting all the tooling setup on your computer can be a daunting task, but getting Docker up and running on your favorite OS has become very easy. -The *getting started* guide on Docker has detailed instructions for setting up Docker on [Mac](https://docs.docker.com/docker-for-mac/), [Linux](https://docs.docker.com/engine/installation/linux/) and [Windows](https://docs.docker.com/docker-for-windows/). +The *getting started* guide on Docker has detailed instructions for setting up Docker on [Mac](https://docs.docker.com/docker-for-mac/), [Linux](https://docs.docker.com/engine/installation/linux/) and [Windows](https://docs.docker.com/docker-for-windows/). + +*If you're using Docker for Windows* make sure you have [shared your drive](https://docs.docker.com/docker-for-windows/#/shared-drives). *Important note* If you're using an older version of Windows or MacOS you may need to use [Docker Machine](https://docs.docker.com/machine/overview/) instead. +*All commandline work in either bash or Powershell on Windows* + Once you are done installing Docker, test your Docker installation by running the following: ``` $ docker run hello-world diff --git a/beginner/chapters/votingapp.md b/beginner/chapters/votingapp.md index f6c3bb4cdb..820c625374 100644 --- a/beginner/chapters/votingapp.md +++ b/beginner/chapters/votingapp.md @@ -33,15 +33,15 @@ In the folder ```example-voting-app/voting-app``` you need to edit the app.py an Edit the following lines: ``` -option_a = os.getenv('OPTION_A', "Java") -option_b = os.getenv('OPTION_B', "Python") +option_a = os.getenv('OPTION_A', "Cats") +option_b = os.getenv('OPTION_B', "Dogs") ``` substituting two options of your choice. For instance: ``` -option_a = os.getenv('OPTION_A', "Cats") -option_b = os.getenv('OPTION_B', "Dogs") +option_a = os.getenv('OPTION_A', "Java") +option_b = os.getenv('OPTION_B', ".NET") ``` #### 3.2.2 Running your app Now, run your application. To do that, we'll use [Docker Compose](https://docs.docker.com/compose). Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you define a `.yml` file that describes all the containers and volumes that you want, and the networks between them. In the example-voting-app directory, you'll see a `docker-compose.yml file`: @@ -71,9 +71,7 @@ services: - back-tier worker: - image: manomarks/worker - networks: - - back-tier + build: ./worker redis: image: redis:alpine @@ -103,10 +101,10 @@ This Compose file defines - A voting-app container based on a Python image - A result-app container based on a Node.js image - A redis container based on a redis image, to temporarily store the data. -- A Java based worker app based on a Java image +- A .NET based worker app based on a .NET image - A Postgres container based on a postgres image -Note that three of the containers are built from Dockerfiles, while the other two are images on Docker Hub. To learn more about how they're built, you can examine each of the Dockerfiles in the two directories: `voting-app`, `result-app`. We included the code for the Java worker in `worker` but pre-built the image to save on downloads. +Note that three of the containers are built from Dockerfiles, while the other two are images on Docker Hub. To learn more about how they're built, you can examine each of the Dockerfiles in the three directories: `vote`, `result`, `worker`. The Compose file also defines two networks, front-tier and back-tier. Each container is placed on one or two networks. Once on those networks, they can access other services on that network in code just by using the name of the service. To learn more about networking check out the [Networking with Compose documentation](https://docs.docker.com/compose/networking/). diff --git a/beginner/chapters/webapps.md b/beginner/chapters/webapps.md index 9c597c12d3..8a8db12fd8 100644 --- a/beginner/chapters/webapps.md +++ b/beginner/chapters/webapps.md @@ -89,8 +89,8 @@ Now that you've seen how to run a webserver inside a Docker image, how do you cr But first, let's stop and remove the containers since you won't be using them anymore. ``` -$ docker stop static-site static-site -$ docker rm static-site static-site +$ docker stop static-site +$ docker rm static-site ``` Let's use a shortcut to remove the second site: From 0cf81676bcc3a7698f41203c71f7e0147fcfb8dd Mon Sep 17 00:00:00 2001 From: Mano Marks Date: Thu, 22 Sep 2016 14:29:20 -0700 Subject: [PATCH 2/4] removing quickstart as it is duplicative. Renaming beginner to cloud-quick-start --- swarm-mode/README.md | 3 +- swarm-mode/beginner-tutorial/README.md | 3 +- swarm-mode/beginner/README.md | 170 -------------- swarm-mode/beginner/swarm.sh | 275 ----------------------- swarm-mode/quickstart/README.md | 43 ---- swarm-mode/quickstart/buildswarm-do.sh | 33 --- swarm-mode/quickstart/buildswarm-vbox.sh | 74 ------ 7 files changed, 3 insertions(+), 598 deletions(-) delete mode 100644 swarm-mode/beginner/README.md delete mode 100755 swarm-mode/beginner/swarm.sh delete mode 100644 swarm-mode/quickstart/README.md delete mode 100755 swarm-mode/quickstart/buildswarm-do.sh delete mode 100755 swarm-mode/quickstart/buildswarm-vbox.sh diff --git a/swarm-mode/README.md b/swarm-mode/README.md index dbd77b3bc2..44bbeff121 100644 --- a/swarm-mode/README.md +++ b/swarm-mode/README.md @@ -3,5 +3,4 @@ [Docker Swarm Mode](https://docs.docker.com/engine/swarm/) is a release candidate feature included with Docker Engine 1.12. These tutorials are designed to help you quickly get started testing these new features. * [Docker Swarm Mode full tutorial](beginner-tutorial/README.md) -* [Swarm quickstart tutorial](quickstart/README.md) -* [Service deployment on a swarm](beginner/README.md) \ No newline at end of file +* [Service deployment on a swarm in the Cloud](cloud-quick-start/README.md) diff --git a/swarm-mode/beginner-tutorial/README.md b/swarm-mode/beginner-tutorial/README.md index d83b3a5c8e..d66f7139ab 100644 --- a/swarm-mode/beginner-tutorial/README.md +++ b/swarm-mode/beginner-tutorial/README.md @@ -382,4 +382,5 @@ Successfully removed manager3 ``` ## Next steps -Next, check out the documentation on [Docker Swarm Mode](https://docs.docker.com/engine/swarm/) for more information. +We have a similar tutorial using Docker Machine to do [Service deployment on a swarm in the Cloud](../cloud-quick-start/README.md). +Also check out the documentation on [Docker Swarm Mode](https://docs.docker.com/engine/swarm/) for more information. diff --git a/swarm-mode/beginner/README.md b/swarm-mode/beginner/README.md deleted file mode 100644 index c87cf78146..0000000000 --- a/swarm-mode/beginner/README.md +++ /dev/null @@ -1,170 +0,0 @@ -# Service deployment on a swarm - -Script that create a swarm cluster and deploy a simple service. -Swarm is created with Swarm mode of Engine 1.12. Can be created on -* Virtualbox -* Microsoft Azure -* Digitalocean -* Amazon EC2 - -Note: currently, if deploying on AWS, only EU (Ireland) region is available. Make sure you use a Key Pairs for this region - -# Usage - -``` -./swarm.sh [--driver provider] - [--azure-subscription-id azure_subscription_id] - [--amazonec2-access-key ec2_access_key] - [--amazonec2-secret-key ec2_secret_key] - [--amazonec2-security-group ec2_security_group] - [--digitalocean_token] - [-m|--manager nbr_manager] - [-w|--worker nbr_worker] - [-r|--replica nbr_replica] - [-p|--port exposed_port] - [--service_image image_of_the_service_to_deploy] - [--service_port port_exposed_by_the_service_to_deploy] -``` - -Several parameters can be provided -* driver used ("azure", "virtualbox", "digitalocean", "amazonec2") (default: "virtualbox") -* number of manager (default: 3) -* number of worker (default: 5) -* number of replicas for the deployed service (lucj/randomcity:1.1) (default: 5) -* port exposed by the cluster (default: 8080) -* azure subscription id (if azure driver selected) -* digitalocean token (if digitalocean driver specified) -* amazon access key, secret key, security group (currently only for EU (Ireland) region) (if amazonec2 driver is specified) - -# Example - -Let's create a swarm cluster with 2 manager and 2 worker nodes locally (with virtualbox) and using service lucj/randomCity -Once deployed service will be available on port 8080 (default port) - -``` -$ ./swarm.sh --manager 2 --worker 2 --service_image lucj/randomCity --service_port 80 --> about to create a swarm with 2 manager(s) and 2 workers on virtualbox machines --> creating Docker host for manager 1 (please wait) --> creating Docker host for manager 2 (please wait) --> creating Docker host for worker 1 (please wait) --> creating Docker host for worker 2 (please wait) --> init swarm -Swarm initialized: current node (99xi3bzlgobxmeff573qitctg) is now a manager. --> join manager 2 to the swarm -Node f4wocnel60xwfn2z522a645ba accepted in the swarm. --> join worker 1 to the swarm -This node joined a Swarm as a worker. --> join worker 2 to the swarm -This node joined a Swarm as a worker. --> deploy service with 5 replicas with exposed port 8080 --> waiting for service 5ny5u5pmfw75mnomleb34a3kp to be available -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds -... retrying in 2 seconds --> service available on port 8080 of any node -ID NAME REPLICAS IMAGE COMMAND -5ny5u5pmfw75 city 5/5 lucj/randomcity:1.1 -ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE -1j157qz7nu4kaqmack4zuwibm city.1 city lucj/randomcity:1.1 Running 20 seconds Running manager1 -72y2off8y5f8zp4djzmjdzowg city.2 city lucj/randomcity:1.1 Running 20 seconds Running worker1 -efzaweh8lhj9aalrgdhnx26i0 city.3 city lucj/randomcity:1.1 Running 20 seconds Running manager2 -1f5ccot3wn3yhrhfbqf6vj5d5 city.4 city lucj/randomcity:1.1 Running 20 seconds Running worker2 -f53ummqn8mba0hzy15w08pxj4 city.5 city lucj/randomcity:1.1 Running 20 seconds Running worker2 -``` - - -# Docker hosts - -List all Docker host created - -``` -$ docker-machine ls -NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS -manager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0-rc2 -manager2 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0-rc2 -worker1 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0-rc2 -worker2 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0-rc2 -``` - -# Service details - -The test service deployed is a simple http server that returns a message with -* the ip of the container that handled the request -* a random city of the world - -# Test deployed service - -Send several requests to the manager1 - -``` -$ curl 192.168.99.100:8080 -{"message":"10.255.0.7 suggests to visit Zebunto"} -$ curl 192.168.99.100:8080 -{"message":"10.255.0.8 suggests to visit Areugpip"} -$ curl 192.168.99.100:8080 -{"message":"10.255.0.10 suggests to visit Fozbovsav"} -$ curl 192.168.99.100:8080 -{"message":"10.255.0.9 suggests to visit Kitunweg"} -$ curl 192.168.99.100:8080 -{"message":"10.255.0.11 suggests to visit Aviznuk"} -$ curl 192.168.99.100:8080 -{"message":"10.255.0.7 suggests to visit Nedhikmu"} -$ curl 192.168.99.100:8080 -{"message":"10.255.0.8 suggests to visit Palmenme"} -``` - -Send several requests to the worker2 - -``` -$ curl http://192.168.99.102:8080 -{"message":"10.255.0.8 suggests to visit Wehappap"} -$ curl http://192.168.99.102:8080 -{"message":"10.255.0.11 suggests to visit Jocuvdam"} -$ curl http://192.168.99.102:8080 -{"message":"10.255.0.12 suggests to visit Suvigenuh"} -$ curl http://192.168.99.102:8080 -{"message":"10.255.0.9 suggests to visit Jinonat"} -``` - -The requests are dispatched in a round robin fashion to the running containers. - -# Examples with other drivers - -## Run 3 managers and 6 workers on Microsoft Azure based on ehazlett/docker-demo image (default image if none specified) - -``` -./swarm.sh --driver azure --azure-subscription-id $AZURE_SUBSCRIPTION_ID --manager 3 --worker 6 -``` - -## Run 3 managers and 6 workers on DigitalOcean and use service based on ehazlett/docker-demo image (default image if none specified) - -``` -./swarm.sh --driver digitalocean --digitalocean_token $DO_TOKEN --manager 3 --worker 6 -``` - -Once the service is deployed you got some nice Mobydock :) - -![Mobydock](https://dl.dropboxusercontent.com/u/2330187/docker/labs/1.12/swarm-sample/mobydock.png) - -Note: beware of the browser cache that prevents the hostname to be updated sometimes - -## Run 3 managers and 6 workers on AmazonEC2 based on ehazlett/docker-demo image (default image if none specified) - -``` -./swarm.sh --driver amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY --amazonec2-secret-key $AWS_SECRET_KEY --amazonec2-security-group default --manager 3 --worker 6 -``` - -note: make sure the security group provided (**default** in this example) allow communication between hosts and open the exposed port (8080 by default) to the outside - -# Status - -- [ ] Azure deployment with image / size / region selection -- [ ] DigitalOcean deployment with image / size / region selection -- [ ] Amazon deployment with AMI / instance type / region selection -- [ ] Amazon deployment with automatic opening of exposed port in SecurityGroup diff --git a/swarm-mode/beginner/swarm.sh b/swarm-mode/beginner/swarm.sh deleted file mode 100755 index 0e99439668..0000000000 --- a/swarm-mode/beginner/swarm.sh +++ /dev/null @@ -1,275 +0,0 @@ -# Default cluster: -# - 3 manager node -# - 5 worker nodes -# - 5 replicas for the test service -# - service image: ehazlett/docker-demo -# - service port: 8080 (port exposed by the service) -# - exposed port: 8080 (port exposed to the outside) -DRIVER="virtualbox" -NBR_MANAGER=3 -NBR_WORKER=5 -NBR_REPLICA=5 -SERVICE_IMAGE="ehazlett/docker-demo" -SERVICE_PORT=8080 -EXPOSED_PORT=8080 - -# additional flags depending upon driver selection -ADDITIONAL_PARAMS= -PERMISSION= -PRIVATE= - -# Manager and worker prefix -PREFIX=$(date "+%Y%m%dT%H%M%S") -MANAGER=${PREFIX}-manager -WORKER=${PREFIX}-worker - -function usage { - echo "Usage: $0 [--driver provider] [--azure-subscription-id] [--amazonec2-access-key ec2_access_key] [--amazonec2-secret-key ec2_secret_key] [--amazonec2-security-group ec2_security_group] [--do_token do_token][-m|--manager nbr_manager] [-w|--worker nbr_worker] [-r|--replica nbr_replica] [-p|--port exposed_port] [--service_image service_image] [--service_port service_port]" - exit 1 -} - -function error { - echo "Error $1" - exit 1 -} - -while [ "$#" -gt 0 ]; do - case "$1" in - --driver|-d) - DRIVER="$2" - shift 2 - ;; - --manager|-m) - NBR_MANAGER="$2" - shift 2 - ;; - --worker|-w) - NBR_WORKER="$2" - shift 2 - ;; - --service_image) - SERVICE_IMAGE="$2" - shift 2 - ;; - --service_port) - SERVICE_PORT="$2" - shift 2 - ;; - --replica|-r) - NBR_REPLICA="$2" - shift 2 - ;; - --port|-p) - EXPOSED_PORT="$2" - shift 2 - ;; - --digitalocean_token) - DO_TOKEN="$2" - shift 2 - ;; - --amazonec2-access-key) - EC2_ACCESS_KEY="$2" - shift 2 - ;; - --amazonec2-secret-key) - EC2_SECRET_KEY="$2" - shift 2 - ;; - --amazonec2-security-group) - EC2_SECURITY_GROUP="$2" - shift 2 - ;; - --azure-subscription-id) - AZURE_SUBSCRIPTION_ID="$2" - shift 2 - ;; - -h|--help) - usage - ;; - esac -done - -# Value of driver parameter's value must be among "azure", "digitalocean", "amazonec2", "virtualbox" (if no value is provided, "virtualbox" driver is used) -if [ "$DRIVER" != "virtualbox" -a "$DRIVER" != "digitalocean" -a "$DRIVER" != "amazonec2" -a "$DRIVER" != "azure" ];then - error "driver value must be among azure, digitalocean, amazonec2, virtualbox" -fi - -# No additional parameters needed for virtualbox driver -if [ "$DRIVER" == "virtualbox" ]; then - echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines" -fi - -# Make sure mandatory parameter for digitalocean driver -if [ "$DRIVER" == "digitalocean" ]; then - ADDITIONAL_PARAMS="--digitalocean-access-token=${DO_TOKEN} --digitalocean-region=lon1 --digitalocean-size=1gb --digitalocean-image=ubuntu-14-04-x64 --engine-install-url=https://test.docker.com" - echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (lon1 / 1gb / Ubuntu 14.04)" -fi - -# Make sure mandatory parameter for amazonec2 driver -if [ "$DRIVER" == "amazonec2" ];then - if [ "$EC2_ACCESS_KEY" == "" ];then - error "--amazonec2-access-key must be provided" - fi - if [ "$EC2_SECRET_KEY" == "" ];then - error "--amazonec2-secret-key must be provided" - fi - if [ "$EC2_SECURITY_GROUP" == "" ];then - error "--amazonec2-security-group must be provided (+ make sure this one allows inter hosts communication and is has opened port $EXPOSED_PORT to the outside" - fi - PERMISSION="sudo" - ADDITIONAL_PARAMS="--amazonec2-access-key ${EC2_ACCESS_KEY} --amazonec2-secret-key ${EC2_SECRET_KEY} --amazonec2-security-group ${EC2_SECURITY_GROUP} --amazonec2-security-group docker-machine --amazonec2-region eu-west-1 --amazonec2-instance-type t2.micro --amazonec2-ami ami-f95ef58a --engine-install-url=https://test.docker.com" - echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (eu-west-1 / t2.micro / Ubuntu 14.04)" -fi - -# Make sure mandatory parameter for azure driver -if [ "$DRIVER" == "azure" ];then - if [ "$AZURE_SUBSCRIPTION_ID" == "" ];then - error "--azure-subscription-id must be provided" - fi - # For Azure Storage Container the Manager and Worker prefix must be lowercase - PREFIX=$(date "+%Y%m%dt%H%M%S") - MANAGER=${PREFIX}-manager - WORKER=${PREFIX}-worker - - PERMISSION="sudo" - ADDITIONAL_PARAMS="--driver azure --azure-subscription-id ${AZURE_SUBSCRIPTION_ID} --azure-open-port ${EXPOSED_PORT}" - echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (westus / Standard_A2 / Ubuntu 15.10)" -fi - -echo "-> service is based on image ${SERVICE_IMAGE} exposing port ${SERVICE_PORT}" -echo "-> once deployed service will be accessible via port ${EXPOSED_PORT} to the outside" - -echo -n "is that correct ? ([Y]/N)" -read build_demo - -if [ "$build_demo" = "N" ]; then - echo "aborted !" - exit 0 -fi - -# Get Private vs Public IP -function getIP { - if [ "$DRIVER" == "amazonec2" ]; then - echo $(docker-machine inspect -f '{{ .Driver.PrivateIPAddress }}' $1) - elif [ "$DRIVER" == "azure" ]; then - echo $(docker-machine ssh $1 ifconfig eth0 | awk '/inet addr/{print substr($2,6)}') - else - echo $(docker-machine inspect -f '{{ .Driver.IPAddress }}' $1) - fi -} - -function check_status { - if [ "$(docker-machine ls -f '{{ .Name }}' | grep ${MANAGER}1)" != "" ]; then - error "${MANAGER}1 already exist. Please remove managerX and workerY machines" - fi -} - -function get_manager_token { - echo $(docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm join-token manager -q) -} - -function get_worker_token { - echo $(docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm join-token worker -q) -} - -# Create Docker host for managers -function create_manager { - for i in $(seq 1 $NBR_MANAGER); do - echo "-> creating Docker host for manager $i (please wait)" - # Azure needs Stdout for authentication. Workaround: Show Stdout on first Manager. - if [ "$DRIVER" == "azure" ] && [ "$i" -eq 1 ];then - docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i - else - docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i 1>/dev/null - fi - done -} - -# Create Docker host for workers -function create_workers { - for i in $(seq 1 $NBR_WORKER); do - echo "-> creating Docker host for worker $i (please wait)" - docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${WORKER}$i 1>/dev/null - done -} - -# Init swarm from first manager -function init_swarm { - echo "-> init swarm from ${MANAGER}1" - docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm init --listen-addr $(getIP ${MANAGER}1):2377 --advertise-addr $(getIP ${MANAGER}1):2377 -} - -# Join other managers to the cluster -function join_other_managers { - if [ "$((NBR_MANAGER-1))" -ge "1" ];then - for i in $(seq 2 $NBR_MANAGER);do - echo "-> ${MANAGER}$i requests membership to the swarm" - docker-machine ssh ${MANAGER}$i $PERMISSION docker swarm join --token $(get_manager_token) --listen-addr $(getIP ${MANAGER}$i):2377 --advertise-addr $(getIP ${MANAGER}$i):2377 $(getIP ${MANAGER}1):2377 2>&1 - done - fi -} - -# Join worker to the cluster -function join_workers { - for i in $(seq 1 $NBR_WORKER);do - echo "-> join worker $i to the swarm" - docker-machine ssh ${WORKER}$i $PERMISSION docker swarm join --token $(get_worker_token) --listen-addr $(getIP ${WORKER}$i):2377 --advertise-addr $(getIP ${WORKER}$i):2377 $(getIP ${MANAGER}1):2377 - done -} - -# Deploy a test service -function deploy_service { - echo "-> deploy service with $NBR_REPLICA replicas with exposed port $EXPOSED_PORT" - SERVICE_ID=$(docker-machine ssh ${MANAGER}1 $PERMISSION docker service create --name demo --replicas $NBR_REPLICA --publish "${EXPOSED_PORT}:${SERVICE_PORT}" ${SERVICE_IMAGE}) - if [ "${SERVICE_ID}" == "" ]; then - error "deploying service: no id returned" - fi -} - -# Wait for service to be available -function wait_service { - echo "-> waiting for service ${SERVICE_ID} to be available" - - TASKS_NBR=$(docker-machine ssh ${MANAGER}1 $PERMISSION docker service ls | grep demo | awk '{print $3}' | cut -d '/' -f1) - - while [ "$TASKS_NBR" -lt "$NBR_REPLICA" ]; do - echo "... retrying in 2 seconds" - sleep 2 - TASKS_NBR=$(docker-machine ssh ${MANAGER}1 $PERMISSION docker service ls | grep demo | awk '{print $3}' | cut -d '/' -f1) - done -} - -# Display status -function status { - echo "-> service available on port $EXPOSED_PORT of any node" - - echo "-> list available service" - docker-machine ssh ${MANAGER}1 $PERMISSION docker service ls - echo - echo "-> list tasks" - echo - docker-machine ssh ${MANAGER}1 $PERMISSION docker service ps demo - echo - echo "-> list machines" - docker-machine ls | egrep $PREFIX - echo - if [ "$DRIVER" == "amazonec2" ]; then - echo "#####" - echo "Warning: make sure you opened the port $EXPOSED_PORT in AWS security group used" - echo "#####" - fi -} - -function main { - check_status - create_manager - create_workers - init_swarm - join_other_managers - join_workers - deploy_service - wait_service - status -} - -main diff --git a/swarm-mode/quickstart/README.md b/swarm-mode/quickstart/README.md deleted file mode 100644 index 411583efbc..0000000000 --- a/swarm-mode/quickstart/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# docker swarm - -Get in touch with the new `docker swarm` feature in Docker 1.12. - -## Build a local swarm with Docker Machine - -To create a local swarm with Docker Machine use the following script - -```bash -./buildswarm-vbox.sh -``` - -It will create two VirtualBox machines `sw01` and `sw02`. The machine `sw01` is -the swarm manager, the machine `sw02` joins the swarm. - -To run further commands, just login to the machine `sw01` with - -```bash -docker-machine ssh sw01 -``` - -or run each command through ssh, eg. - -```bash -docker-machine ssh sw01 docker node ls -ID NAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS LEADER -0j9p42jcyur9a * sw01 Accepted Ready Active Reachable Yes -16cznbhxupre5 sw02 Accepted Ready Active -``` - -### Remote swarm with Docker Machine at DigitalOcean - -To build a multi machine swarm at DigitalOcean, run this script with your token. - -```bash -DO_TOKEN=xxxx ./buildswarm-do.sh -``` - -Then control your swarm with commands on your swarm manager node - -```bash -docker-machine ssh do-sw01 docker node ls -``` diff --git a/swarm-mode/quickstart/buildswarm-do.sh b/swarm-mode/quickstart/buildswarm-do.sh deleted file mode 100755 index de24cd026f..0000000000 --- a/swarm-mode/quickstart/buildswarm-do.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -SIZE=2gb -REGION=ams2 -IMAGE=ubuntu-15-10-x64 - -PREFIX=do - -# create swarm manager -docker-machine create \ - --driver=digitalocean \ - --digitalocean-access-token=${DO_TOKEN} \ - --digitalocean-size=${SIZE} \ - --digitalocean-region=${REGION} \ - --digitalocean-private-networking=true \ - --digitalocean-image=${IMAGE} \ - --engine-install-url=https://test.docker.com \ - ${PREFIX}-sw01 -docker-machine ssh ${PREFIX}-sw01 docker swarm init --listen-addr $(docker-machine ip ${PREFIX}-sw01):2377 - -# create another swarm node -docker-machine create \ - --driver=digitalocean \ - --digitalocean-access-token=${DO_TOKEN} \ - --digitalocean-size=${SIZE} \ - --digitalocean-region=${REGION} \ - --digitalocean-private-networking=true \ - --digitalocean-image=${IMAGE} \ - --engine-install-url=https://test.docker.com \ - ${PREFIX}-sw02 -docker-machine ssh ${PREFIX}-sw02 docker swarm join --listen-addr $(docker-machine ip ${PREFIX}-sw02):2377 $(docker-machine ip ${PREFIX}-sw01):2377 - -# list nodes -docker-machine ssh ${PREFIX}-sw01 docker node ls diff --git a/swarm-mode/quickstart/buildswarm-vbox.sh b/swarm-mode/quickstart/buildswarm-vbox.sh deleted file mode 100755 index 52fb648899..0000000000 --- a/swarm-mode/quickstart/buildswarm-vbox.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -# Swarm mode using Docker Machine - -managers=3 -workers=3 - -# create manager machines -echo "======> Creating $managers manager machines ..."; -for node in $(seq 1 $managers); -do - echo "======> Creating manager$node machine ..."; - docker-machine create -d virtualbox manager$node; -done - -# create worker machines -echo "======> Creating $workers worker machines ..."; -for node in $(seq 1 $workers); -do - echo "======> Creating worker$node machine ..."; - docker-machine create -d virtualbox worker$node; -done - -# list all machines -docker-machine ls - -# initialize swarm mode and create a manager -echo "======> Initializing first swarm manager ..." -docker-machine ssh manager1 "docker swarm init --listen-addr $(docker-machine ip manager1) --advertise-addr $(docker-machine ip manager1)" - -# get manager and worker tokens -export manager_token=`docker-machine ssh manager1 "docker swarm join-token manager -q"` -export worker_token=`docker-machine ssh manager1 "docker swarm join-token worker -q"` - -echo "manager_token: $manager_token" -echo "worker_token: $worker_token" - -# other masters join swarm -for node in $(seq 2 $managers); -do - echo "======> manager$node joining swarm as manager ..." - docker-machine ssh manager$node \ - "docker swarm join \ - --token $manager_token \ - --listen-addr $(docker-machine ip manager$node) \ - --advertise-addr $(docker-machine ip manager$node) \ - $(docker-machine ip manager1)" -done - -# show members of swarm -docker-machine ssh manager1 "docker node ls" - -# workers join swarm -for node in $(seq 1 $workers); -do - echo "======> worker$node joining swarm as worker ..." - docker-machine ssh worker$node \ - "docker swarm join \ - --token $worker_token \ - --listen-addr $(docker-machine ip worker$node) \ - --advertise-addr $(docker-machine ip worker$node) \ - $(docker-machine ip manager1):2377" -done - -# show members of swarm -docker-machine ssh manager1 "docker node ls" - -# Cleanup -# # Stop machines -# docker-machine stop worker1 worker2 worker3 manager1 manager2 manager3 - -# # remove machines -# docker-machine rm worker1 worker2 worker3 manager1 manager2 manager3 - From e13451e6e4ddbc95ec30fb99693af12c60b8e4a7 Mon Sep 17 00:00:00 2001 From: Mano Marks Date: Thu, 22 Sep 2016 14:31:20 -0700 Subject: [PATCH 3/4] adding in cloud-quick-start --- swarm-mode/cloud-quick-start/README.md | 170 +++++++++++++++ swarm-mode/cloud-quick-start/swarm.sh | 275 +++++++++++++++++++++++++ 2 files changed, 445 insertions(+) create mode 100644 swarm-mode/cloud-quick-start/README.md create mode 100644 swarm-mode/cloud-quick-start/swarm.sh diff --git a/swarm-mode/cloud-quick-start/README.md b/swarm-mode/cloud-quick-start/README.md new file mode 100644 index 0000000000..1ca6745462 --- /dev/null +++ b/swarm-mode/cloud-quick-start/README.md @@ -0,0 +1,170 @@ +# Service deployment on a swarm in the Cloud + +Script that create a swarm cluster and deploy a simple service. +Swarm is created with Swarm mode of Engine 1.12. Can be created on +* Virtualbox +* Microsoft Azure +* Digitalocean +* Amazon EC2 + +Note: currently, if deploying on AWS, only EU (Ireland) region is available. Make sure you use a Key Pairs for this region + +# Usage + +``` +./swarm.sh [--driver provider] + [--azure-subscription-id azure_subscription_id] + [--amazonec2-access-key ec2_access_key] + [--amazonec2-secret-key ec2_secret_key] + [--amazonec2-security-group ec2_security_group] + [--digitalocean_token] + [-m|--manager nbr_manager] + [-w|--worker nbr_worker] + [-r|--replica nbr_replica] + [-p|--port exposed_port] + [--service_image image_of_the_service_to_deploy] + [--service_port port_exposed_by_the_service_to_deploy] +``` + +Several parameters can be provided +* driver used ("azure", "virtualbox", "digitalocean", "amazonec2") (default: "virtualbox") +* number of manager (default: 3) +* number of worker (default: 5) +* number of replicas for the deployed service (lucj/randomcity:1.1) (default: 5) +* port exposed by the cluster (default: 8080) +* azure subscription id (if azure driver selected) +* digitalocean token (if digitalocean driver specified) +* amazon access key, secret key, security group (currently only for EU (Ireland) region) (if amazonec2 driver is specified) + +# Example + +Let's create a swarm cluster with 2 manager and 2 worker nodes locally (with virtualbox) and using service lucj/randomCity +Once deployed service will be available on port 8080 (default port) + +``` +$ ./swarm.sh --manager 2 --worker 2 --service_image lucj/randomCity --service_port 80 +-> about to create a swarm with 2 manager(s) and 2 workers on virtualbox machines +-> creating Docker host for manager 1 (please wait) +-> creating Docker host for manager 2 (please wait) +-> creating Docker host for worker 1 (please wait) +-> creating Docker host for worker 2 (please wait) +-> init swarm +Swarm initialized: current node (99xi3bzlgobxmeff573qitctg) is now a manager. +-> join manager 2 to the swarm +Node f4wocnel60xwfn2z522a645ba accepted in the swarm. +-> join worker 1 to the swarm +This node joined a Swarm as a worker. +-> join worker 2 to the swarm +This node joined a Swarm as a worker. +-> deploy service with 5 replicas with exposed port 8080 +-> waiting for service 5ny5u5pmfw75mnomleb34a3kp to be available +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +... retrying in 2 seconds +-> service available on port 8080 of any node +ID NAME REPLICAS IMAGE COMMAND +5ny5u5pmfw75 city 5/5 lucj/randomcity:1.1 +ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE +1j157qz7nu4kaqmack4zuwibm city.1 city lucj/randomcity:1.1 Running 20 seconds Running manager1 +72y2off8y5f8zp4djzmjdzowg city.2 city lucj/randomcity:1.1 Running 20 seconds Running worker1 +efzaweh8lhj9aalrgdhnx26i0 city.3 city lucj/randomcity:1.1 Running 20 seconds Running manager2 +1f5ccot3wn3yhrhfbqf6vj5d5 city.4 city lucj/randomcity:1.1 Running 20 seconds Running worker2 +f53ummqn8mba0hzy15w08pxj4 city.5 city lucj/randomcity:1.1 Running 20 seconds Running worker2 +``` + + +# Docker hosts + +List all Docker host created + +``` +$ docker-machine ls +NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS +manager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0-rc2 +manager2 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0-rc2 +worker1 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0-rc2 +worker2 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0-rc2 +``` + +# Service details + +The test service deployed is a simple http server that returns a message with +* the ip of the container that handled the request +* a random city of the world + +# Test deployed service + +Send several requests to the manager1 + +``` +$ curl 192.168.99.100:8080 +{"message":"10.255.0.7 suggests to visit Zebunto"} +$ curl 192.168.99.100:8080 +{"message":"10.255.0.8 suggests to visit Areugpip"} +$ curl 192.168.99.100:8080 +{"message":"10.255.0.10 suggests to visit Fozbovsav"} +$ curl 192.168.99.100:8080 +{"message":"10.255.0.9 suggests to visit Kitunweg"} +$ curl 192.168.99.100:8080 +{"message":"10.255.0.11 suggests to visit Aviznuk"} +$ curl 192.168.99.100:8080 +{"message":"10.255.0.7 suggests to visit Nedhikmu"} +$ curl 192.168.99.100:8080 +{"message":"10.255.0.8 suggests to visit Palmenme"} +``` + +Send several requests to the worker2 + +``` +$ curl http://192.168.99.102:8080 +{"message":"10.255.0.8 suggests to visit Wehappap"} +$ curl http://192.168.99.102:8080 +{"message":"10.255.0.11 suggests to visit Jocuvdam"} +$ curl http://192.168.99.102:8080 +{"message":"10.255.0.12 suggests to visit Suvigenuh"} +$ curl http://192.168.99.102:8080 +{"message":"10.255.0.9 suggests to visit Jinonat"} +``` + +The requests are dispatched in a round robin fashion to the running containers. + +# Examples with other drivers + +## Run 3 managers and 6 workers on Microsoft Azure based on ehazlett/docker-demo image (default image if none specified) + +``` +./swarm.sh --driver azure --azure-subscription-id $AZURE_SUBSCRIPTION_ID --manager 3 --worker 6 +``` + +## Run 3 managers and 6 workers on DigitalOcean and use service based on ehazlett/docker-demo image (default image if none specified) + +``` +./swarm.sh --driver digitalocean --digitalocean_token $DO_TOKEN --manager 3 --worker 6 +``` + +Once the service is deployed you got some nice Mobydock :) + +![Mobydock](https://dl.dropboxusercontent.com/u/2330187/docker/labs/1.12/swarm-sample/mobydock.png) + +Note: beware of the browser cache that prevents the hostname to be updated sometimes + +## Run 3 managers and 6 workers on AmazonEC2 based on ehazlett/docker-demo image (default image if none specified) + +``` +./swarm.sh --driver amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY --amazonec2-secret-key $AWS_SECRET_KEY --amazonec2-security-group default --manager 3 --worker 6 +``` + +note: make sure the security group provided (**default** in this example) allow communication between hosts and open the exposed port (8080 by default) to the outside + +# Status + +- [ ] Azure deployment with image / size / region selection +- [ ] DigitalOcean deployment with image / size / region selection +- [ ] Amazon deployment with AMI / instance type / region selection +- [ ] Amazon deployment with automatic opening of exposed port in SecurityGroup diff --git a/swarm-mode/cloud-quick-start/swarm.sh b/swarm-mode/cloud-quick-start/swarm.sh new file mode 100644 index 0000000000..0e99439668 --- /dev/null +++ b/swarm-mode/cloud-quick-start/swarm.sh @@ -0,0 +1,275 @@ +# Default cluster: +# - 3 manager node +# - 5 worker nodes +# - 5 replicas for the test service +# - service image: ehazlett/docker-demo +# - service port: 8080 (port exposed by the service) +# - exposed port: 8080 (port exposed to the outside) +DRIVER="virtualbox" +NBR_MANAGER=3 +NBR_WORKER=5 +NBR_REPLICA=5 +SERVICE_IMAGE="ehazlett/docker-demo" +SERVICE_PORT=8080 +EXPOSED_PORT=8080 + +# additional flags depending upon driver selection +ADDITIONAL_PARAMS= +PERMISSION= +PRIVATE= + +# Manager and worker prefix +PREFIX=$(date "+%Y%m%dT%H%M%S") +MANAGER=${PREFIX}-manager +WORKER=${PREFIX}-worker + +function usage { + echo "Usage: $0 [--driver provider] [--azure-subscription-id] [--amazonec2-access-key ec2_access_key] [--amazonec2-secret-key ec2_secret_key] [--amazonec2-security-group ec2_security_group] [--do_token do_token][-m|--manager nbr_manager] [-w|--worker nbr_worker] [-r|--replica nbr_replica] [-p|--port exposed_port] [--service_image service_image] [--service_port service_port]" + exit 1 +} + +function error { + echo "Error $1" + exit 1 +} + +while [ "$#" -gt 0 ]; do + case "$1" in + --driver|-d) + DRIVER="$2" + shift 2 + ;; + --manager|-m) + NBR_MANAGER="$2" + shift 2 + ;; + --worker|-w) + NBR_WORKER="$2" + shift 2 + ;; + --service_image) + SERVICE_IMAGE="$2" + shift 2 + ;; + --service_port) + SERVICE_PORT="$2" + shift 2 + ;; + --replica|-r) + NBR_REPLICA="$2" + shift 2 + ;; + --port|-p) + EXPOSED_PORT="$2" + shift 2 + ;; + --digitalocean_token) + DO_TOKEN="$2" + shift 2 + ;; + --amazonec2-access-key) + EC2_ACCESS_KEY="$2" + shift 2 + ;; + --amazonec2-secret-key) + EC2_SECRET_KEY="$2" + shift 2 + ;; + --amazonec2-security-group) + EC2_SECURITY_GROUP="$2" + shift 2 + ;; + --azure-subscription-id) + AZURE_SUBSCRIPTION_ID="$2" + shift 2 + ;; + -h|--help) + usage + ;; + esac +done + +# Value of driver parameter's value must be among "azure", "digitalocean", "amazonec2", "virtualbox" (if no value is provided, "virtualbox" driver is used) +if [ "$DRIVER" != "virtualbox" -a "$DRIVER" != "digitalocean" -a "$DRIVER" != "amazonec2" -a "$DRIVER" != "azure" ];then + error "driver value must be among azure, digitalocean, amazonec2, virtualbox" +fi + +# No additional parameters needed for virtualbox driver +if [ "$DRIVER" == "virtualbox" ]; then + echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines" +fi + +# Make sure mandatory parameter for digitalocean driver +if [ "$DRIVER" == "digitalocean" ]; then + ADDITIONAL_PARAMS="--digitalocean-access-token=${DO_TOKEN} --digitalocean-region=lon1 --digitalocean-size=1gb --digitalocean-image=ubuntu-14-04-x64 --engine-install-url=https://test.docker.com" + echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (lon1 / 1gb / Ubuntu 14.04)" +fi + +# Make sure mandatory parameter for amazonec2 driver +if [ "$DRIVER" == "amazonec2" ];then + if [ "$EC2_ACCESS_KEY" == "" ];then + error "--amazonec2-access-key must be provided" + fi + if [ "$EC2_SECRET_KEY" == "" ];then + error "--amazonec2-secret-key must be provided" + fi + if [ "$EC2_SECURITY_GROUP" == "" ];then + error "--amazonec2-security-group must be provided (+ make sure this one allows inter hosts communication and is has opened port $EXPOSED_PORT to the outside" + fi + PERMISSION="sudo" + ADDITIONAL_PARAMS="--amazonec2-access-key ${EC2_ACCESS_KEY} --amazonec2-secret-key ${EC2_SECRET_KEY} --amazonec2-security-group ${EC2_SECURITY_GROUP} --amazonec2-security-group docker-machine --amazonec2-region eu-west-1 --amazonec2-instance-type t2.micro --amazonec2-ami ami-f95ef58a --engine-install-url=https://test.docker.com" + echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (eu-west-1 / t2.micro / Ubuntu 14.04)" +fi + +# Make sure mandatory parameter for azure driver +if [ "$DRIVER" == "azure" ];then + if [ "$AZURE_SUBSCRIPTION_ID" == "" ];then + error "--azure-subscription-id must be provided" + fi + # For Azure Storage Container the Manager and Worker prefix must be lowercase + PREFIX=$(date "+%Y%m%dt%H%M%S") + MANAGER=${PREFIX}-manager + WORKER=${PREFIX}-worker + + PERMISSION="sudo" + ADDITIONAL_PARAMS="--driver azure --azure-subscription-id ${AZURE_SUBSCRIPTION_ID} --azure-open-port ${EXPOSED_PORT}" + echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (westus / Standard_A2 / Ubuntu 15.10)" +fi + +echo "-> service is based on image ${SERVICE_IMAGE} exposing port ${SERVICE_PORT}" +echo "-> once deployed service will be accessible via port ${EXPOSED_PORT} to the outside" + +echo -n "is that correct ? ([Y]/N)" +read build_demo + +if [ "$build_demo" = "N" ]; then + echo "aborted !" + exit 0 +fi + +# Get Private vs Public IP +function getIP { + if [ "$DRIVER" == "amazonec2" ]; then + echo $(docker-machine inspect -f '{{ .Driver.PrivateIPAddress }}' $1) + elif [ "$DRIVER" == "azure" ]; then + echo $(docker-machine ssh $1 ifconfig eth0 | awk '/inet addr/{print substr($2,6)}') + else + echo $(docker-machine inspect -f '{{ .Driver.IPAddress }}' $1) + fi +} + +function check_status { + if [ "$(docker-machine ls -f '{{ .Name }}' | grep ${MANAGER}1)" != "" ]; then + error "${MANAGER}1 already exist. Please remove managerX and workerY machines" + fi +} + +function get_manager_token { + echo $(docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm join-token manager -q) +} + +function get_worker_token { + echo $(docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm join-token worker -q) +} + +# Create Docker host for managers +function create_manager { + for i in $(seq 1 $NBR_MANAGER); do + echo "-> creating Docker host for manager $i (please wait)" + # Azure needs Stdout for authentication. Workaround: Show Stdout on first Manager. + if [ "$DRIVER" == "azure" ] && [ "$i" -eq 1 ];then + docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i + else + docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i 1>/dev/null + fi + done +} + +# Create Docker host for workers +function create_workers { + for i in $(seq 1 $NBR_WORKER); do + echo "-> creating Docker host for worker $i (please wait)" + docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${WORKER}$i 1>/dev/null + done +} + +# Init swarm from first manager +function init_swarm { + echo "-> init swarm from ${MANAGER}1" + docker-machine ssh ${MANAGER}1 $PERMISSION docker swarm init --listen-addr $(getIP ${MANAGER}1):2377 --advertise-addr $(getIP ${MANAGER}1):2377 +} + +# Join other managers to the cluster +function join_other_managers { + if [ "$((NBR_MANAGER-1))" -ge "1" ];then + for i in $(seq 2 $NBR_MANAGER);do + echo "-> ${MANAGER}$i requests membership to the swarm" + docker-machine ssh ${MANAGER}$i $PERMISSION docker swarm join --token $(get_manager_token) --listen-addr $(getIP ${MANAGER}$i):2377 --advertise-addr $(getIP ${MANAGER}$i):2377 $(getIP ${MANAGER}1):2377 2>&1 + done + fi +} + +# Join worker to the cluster +function join_workers { + for i in $(seq 1 $NBR_WORKER);do + echo "-> join worker $i to the swarm" + docker-machine ssh ${WORKER}$i $PERMISSION docker swarm join --token $(get_worker_token) --listen-addr $(getIP ${WORKER}$i):2377 --advertise-addr $(getIP ${WORKER}$i):2377 $(getIP ${MANAGER}1):2377 + done +} + +# Deploy a test service +function deploy_service { + echo "-> deploy service with $NBR_REPLICA replicas with exposed port $EXPOSED_PORT" + SERVICE_ID=$(docker-machine ssh ${MANAGER}1 $PERMISSION docker service create --name demo --replicas $NBR_REPLICA --publish "${EXPOSED_PORT}:${SERVICE_PORT}" ${SERVICE_IMAGE}) + if [ "${SERVICE_ID}" == "" ]; then + error "deploying service: no id returned" + fi +} + +# Wait for service to be available +function wait_service { + echo "-> waiting for service ${SERVICE_ID} to be available" + + TASKS_NBR=$(docker-machine ssh ${MANAGER}1 $PERMISSION docker service ls | grep demo | awk '{print $3}' | cut -d '/' -f1) + + while [ "$TASKS_NBR" -lt "$NBR_REPLICA" ]; do + echo "... retrying in 2 seconds" + sleep 2 + TASKS_NBR=$(docker-machine ssh ${MANAGER}1 $PERMISSION docker service ls | grep demo | awk '{print $3}' | cut -d '/' -f1) + done +} + +# Display status +function status { + echo "-> service available on port $EXPOSED_PORT of any node" + + echo "-> list available service" + docker-machine ssh ${MANAGER}1 $PERMISSION docker service ls + echo + echo "-> list tasks" + echo + docker-machine ssh ${MANAGER}1 $PERMISSION docker service ps demo + echo + echo "-> list machines" + docker-machine ls | egrep $PREFIX + echo + if [ "$DRIVER" == "amazonec2" ]; then + echo "#####" + echo "Warning: make sure you opened the port $EXPOSED_PORT in AWS security group used" + echo "#####" + fi +} + +function main { + check_status + create_manager + create_workers + init_swarm + join_other_managers + join_workers + deploy_service + wait_service + status +} + +main From cf382002b7b4f4f5a203c5d8ac63d90683e6631a Mon Sep 17 00:00:00 2001 From: Mano Marks Date: Thu, 22 Sep 2016 14:54:12 -0700 Subject: [PATCH 4/4] adding comment to bash script in cloud-quick-start --- swarm-mode/cloud-quick-start/swarm.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/swarm-mode/cloud-quick-start/swarm.sh b/swarm-mode/cloud-quick-start/swarm.sh index 0e99439668..6bb89aeb81 100644 --- a/swarm-mode/cloud-quick-start/swarm.sh +++ b/swarm-mode/cloud-quick-start/swarm.sh @@ -1,3 +1,4 @@ +# This will run in bash on Linux, Mac, and Windows 10 Anniverary Edition # Default cluster: # - 3 manager node # - 5 worker nodes @@ -5,6 +6,7 @@ # - service image: ehazlett/docker-demo # - service port: 8080 (port exposed by the service) # - exposed port: 8080 (port exposed to the outside) + DRIVER="virtualbox" NBR_MANAGER=3 NBR_WORKER=5 @@ -82,7 +84,7 @@ while [ "$#" -gt 0 ]; do --azure-subscription-id) AZURE_SUBSCRIPTION_ID="$2" shift 2 - ;; + ;; -h|--help) usage ;; @@ -116,7 +118,7 @@ if [ "$DRIVER" == "amazonec2" ];then if [ "$EC2_SECURITY_GROUP" == "" ];then error "--amazonec2-security-group must be provided (+ make sure this one allows inter hosts communication and is has opened port $EXPOSED_PORT to the outside" fi - PERMISSION="sudo" + PERMISSION="sudo" ADDITIONAL_PARAMS="--amazonec2-access-key ${EC2_ACCESS_KEY} --amazonec2-secret-key ${EC2_SECRET_KEY} --amazonec2-security-group ${EC2_SECURITY_GROUP} --amazonec2-security-group docker-machine --amazonec2-region eu-west-1 --amazonec2-instance-type t2.micro --amazonec2-ami ami-f95ef58a --engine-install-url=https://test.docker.com" echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (eu-west-1 / t2.micro / Ubuntu 14.04)" fi @@ -126,12 +128,12 @@ if [ "$DRIVER" == "azure" ];then if [ "$AZURE_SUBSCRIPTION_ID" == "" ];then error "--azure-subscription-id must be provided" fi - # For Azure Storage Container the Manager and Worker prefix must be lowercase + # For Azure Storage Container the Manager and Worker prefix must be lowercase PREFIX=$(date "+%Y%m%dt%H%M%S") MANAGER=${PREFIX}-manager WORKER=${PREFIX}-worker - PERMISSION="sudo" + PERMISSION="sudo" ADDITIONAL_PARAMS="--driver azure --azure-subscription-id ${AZURE_SUBSCRIPTION_ID} --azure-open-port ${EXPOSED_PORT}" echo "-> about to create a swarm with $NBR_MANAGER manager(s) and $NBR_WORKER workers on $DRIVER machines (westus / Standard_A2 / Ubuntu 15.10)" fi @@ -153,7 +155,7 @@ function getIP { echo $(docker-machine inspect -f '{{ .Driver.PrivateIPAddress }}' $1) elif [ "$DRIVER" == "azure" ]; then echo $(docker-machine ssh $1 ifconfig eth0 | awk '/inet addr/{print substr($2,6)}') - else + else echo $(docker-machine inspect -f '{{ .Driver.IPAddress }}' $1) fi } @@ -176,10 +178,10 @@ function get_worker_token { function create_manager { for i in $(seq 1 $NBR_MANAGER); do echo "-> creating Docker host for manager $i (please wait)" - # Azure needs Stdout for authentication. Workaround: Show Stdout on first Manager. + # Azure needs Stdout for authentication. Workaround: Show Stdout on first Manager. if [ "$DRIVER" == "azure" ] && [ "$i" -eq 1 ];then docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i - else + else docker-machine create --driver $DRIVER $ADDITIONAL_PARAMS ${MANAGER}$i 1>/dev/null fi done @@ -204,7 +206,7 @@ function join_other_managers { if [ "$((NBR_MANAGER-1))" -ge "1" ];then for i in $(seq 2 $NBR_MANAGER);do echo "-> ${MANAGER}$i requests membership to the swarm" - docker-machine ssh ${MANAGER}$i $PERMISSION docker swarm join --token $(get_manager_token) --listen-addr $(getIP ${MANAGER}$i):2377 --advertise-addr $(getIP ${MANAGER}$i):2377 $(getIP ${MANAGER}1):2377 2>&1 + docker-machine ssh ${MANAGER}$i $PERMISSION docker swarm join --token $(get_manager_token) --listen-addr $(getIP ${MANAGER}$i):2377 --advertise-addr $(getIP ${MANAGER}$i):2377 $(getIP ${MANAGER}1):2377 2>&1 done fi } @@ -249,7 +251,7 @@ function status { echo "-> list tasks" echo docker-machine ssh ${MANAGER}1 $PERMISSION docker service ps demo - echo + echo echo "-> list machines" docker-machine ls | egrep $PREFIX echo