{"id":14235547,"url":"https://github.com/tdi/vagrant-docker-swarm","last_synced_at":"2026-01-12T11:33:52.334Z","repository":{"id":48609671,"uuid":"75435232","full_name":"tdi/vagrant-docker-swarm","owner":"tdi","description":"Vagrant playground for Docker Swarm","archived":false,"fork":false,"pushed_at":"2021-07-18T08:30:55.000Z","size":15,"stargazers_count":95,"open_issues_count":0,"forks_count":48,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-09T14:54:11.966Z","etag":null,"topics":["cluster","docker","docker-swarm","playground","swarm-mode","vagrant"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tdi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-02T22:16:55.000Z","updated_at":"2024-10-12T22:38:22.000Z","dependencies_parsed_at":"2022-09-05T07:50:40.540Z","dependency_job_id":null,"html_url":"https://github.com/tdi/vagrant-docker-swarm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdi%2Fvagrant-docker-swarm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdi%2Fvagrant-docker-swarm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdi%2Fvagrant-docker-swarm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdi%2Fvagrant-docker-swarm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdi","download_url":"https://codeload.github.com/tdi/vagrant-docker-swarm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229478663,"owners_count":18079371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cluster","docker","docker-swarm","playground","swarm-mode","vagrant"],"created_at":"2024-08-20T21:02:03.906Z","updated_at":"2026-01-12T11:33:52.310Z","avatar_url":"https://github.com/tdi.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Docker Swarm Vagrant\n\nThis is a simple Vagrantfile which can be used to spin few nodes with Docker 1.12+ installed. You\ncan play with Docker Swarm on it. Boxes are Ubuntu Trusty amd64. \n\n*Note*: This fork updates the original in providing two additional files, Vagrantefile.XENIAL and provision.sh.XENIAL. Replace the originals with these files if you wish to run a newer version of Docker in the Xenial version of Ubuntu. There is an issue with Docker Swarm when using the original files. See this:\n\n[https://github.com/moby/moby/issues/34165]\n\nSo far as I have seen, using the Xenial versions of the files to create and provision the Vagrant nodes fixes this problem.\n\n# Docker Swarm\n\nDocker Swarm is a Docker clustering solution, it turns multiple physical (or virtual) hosts into a one cluster, which practically behaves as a single Docker host. Swarm additionally gives you tools and mechiasms to easily scale your containers and create managed services with automatic load balancing to the exposed ports. \n\nSwarm uses [Raft Consensus Algortihm](http://thesecretlivesofdata.com/raft/) to manage the cluster state. Swarm can tolerate `(N-1)/2` failures and needs `(N/2)+1` nodes to agree on values. \n\n# Customize\n\nBy default `vagrant up` spins up 3 machines: `manager`, `worker1`, `worker2`. You can adjust how many\nworkers you want in the `Vagrantfile`, by setting the `numworkers` variable. Manager, by default, has address \"192.168.10.2\", workers have consecutive ips. \n\n```ruby\nnumworkers = 2\n```\n\nIf your provisioner is `Virtualbox`, you can modify the vm allocations for memory and cpu by changing these variables:\n\n```ruby\nvmmemory = 512\n```\n\n```ruby\nnumcpu = 1\n```\n\n\n`/etc/hosts` on every machine is populated with an IP address and a name of every other machine, so that names are resolved within the cluster. This mechanism is not idempotent, reprovisioning will append the hosts again. \n\n# Auto mode\n\nBy default, vagrant will create pure machines with docker installed. You can run \n`AUTO_START_SWARM=true vagrant up` to provision swarm automatically. You will get an already running Docker swarm cluster.\n\n# Play\n\nAfter starting swarm, you can use my testing Docker image to play with. It is called `darek/goweb` and is a super simple Web app, displaying the hostname, and a version. There are three tags: `1.0`, `2.0` and `latest`. They can be used to play with swarm rolling update feature. The container exposes port 8080. \n\nGo to the master node and start docker swarm:\n\n```bash\n   (host)# vagrant ssh manager\n(manager)# docker swarm init --advertise-addr 192.168.10.2\n\ndocker swarm join \\\n--token SWMTKN-1-59h28hcbb8gzs2xs24oyh7hjvc7fp8skjzvnpw9cksmp96m4y2-35er9ai3u1f1ae5esb7x8l1hx \\\n192.168.10.2:2377\n```\n\nNow join the swarm on the nodes with the command from the manager, do it on both nodes. You can verify that nodes are in the cluster by doing `docker nodes ls` on the manager.\n\n```bash\nvagrant@manager:~$ docker node ls\nID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS\n0rtuyz07e0wazmxvoed1llmx3 *  manager   Ready   Active        Leader\n1iab1w9m5znyzmh7hpzyn7rrw    worker2   Ready   Active\n4mmca5rxrxxhb0tb7s5du5hpe    worker1   Ready   Active\n```\n\nNow create a web service, with 1 replica, on any of the nodes:\n\n```bash\ndocker service create --name web --replicas 1 --publish 8080:8080 darek/goweb:1.0\n```\nYou can see the status od the service with `docker service ps web`. \n```\nvagrant@manager:~$ docker service  ps web\nID                         NAME   IMAGE            NODE     DESIRED STATE  CURRENT STATE           ERROR\n7m0s3ikyjyvps4xgpk655uv9k  web.1  darek/goweb:1.0  manager  Running        Running 16 seconds ago\n```\n\nYou can scale up the service if you want:\n\n```bash \ndocker service scale web=4\n```\n\nNow, let us verify it works, docker swarm will load balance requests to all of the service instances:\n\n```bash\nvagrant ssh worker1\nsudo apt-get install httpie -y\nhttp localhost:8080\n```\nDo the http command serveral times, you will notice different hostnames every time. This is because swarm handler load balancing for us. \n\nLet's do a rolling update of the service, first let's scale it to 10 - you already know how. \nFirst we will update the defintion of the service to say that updates will have a delay of 5s.  \n\n```bash\ndocker service update --update-delay 5s web\n```\nLet's us update the service now:\n\n```bash\ndocker service update --image darek/goweb:2.0 web\n```\nNow docker will update service one by one with a 5s delay between the updates. If you want to introduce parallelism to updates you can specify if with the `--update-parallelism` flag. \n\n```bash \ndocker service update --update-parallelism 2 web\n```\n\nLet's see how it goes:\n\n```bash\nvagrant@manager:~$ docker service ps web\nID                         NAME        IMAGE            NODE     DESIRED STATE  CURRENT STATE                    ERROR\n7m0s3ikyjyvps4xgpk655uv9k  web.1       darek/goweb:1.0  manager  Running        Running 8 minutes ago\nf49k99apn8yzve0uh8zsyigw6  web.2       darek/goweb:1.0  worker1  Running        Running 7 minutes ago\n8t9x9qqqxztzd8msuccbx43mg  web.3       darek/goweb:2.0  manager  Running        Running 11 seconds ago\n38pl9czfhaztifjsb605wi2m9   \\_ web.3   darek/goweb:1.0  worker1  Shutdown       Shutdown 16 seconds ago\n5y4iaxmv1jhdw5b7qroessmr9  web.4       darek/goweb:1.0  worker2  Running        Running 7 minutes ago\n2zhfna5m15cd482hbt06kc139  web.5       darek/goweb:2.0  worker1  Running        Preparing 1 seconds ago\n3ydym0s1iq0psko60zi66ojvs   \\_ web.5   darek/goweb:1.0  manager  Shutdown       Shutdown less than a second ago\n9feao0z26oc75qgoktuc16pro  web.6       darek/goweb:1.0  manager  Running        Running about a minute ago\n14tsult13blurmrh2klf7sm7i  web.7       darek/goweb:2.0  worker2  Running        Running 43 seconds ago\n1qtcsaohat94puoym9i6zsadf   \\_ web.7   darek/goweb:1.0  manager  Shutdown       Shutdown 48 seconds ago\n8d2qnv19urq2yzlmqzud41ffa  web.8       darek/goweb:1.0  worker2  Running        Running about a minute ago\n9shytfqyotuuyaj5hiddnymd4  web.9       darek/goweb:1.0  worker2  Running        Running about a minute ago\n9kr6ehtv093cnmdxo55sy4pl9  web.10      darek/goweb:2.0  worker1  Running        Running 27 seconds ago\n1yvwgb25d8fbarrabyeqha843   \\_ web.10  darek/goweb:1.0  worker1  Shutdown       Shutdown 31 seconds ago\n```\n\nSome services are already updated. Nice.\n\nYou can also inspect the service by `docker service inspect --pretty web`. \n\n```bash\nvagrant@manager:~$ docker service inspect --pretty web\nID:\t\t0iqjzgky9p7ilky60xff4ovgt\nName:\t\tweb\nMode:\t\tReplicated\n Replicas:\t10\nUpdate status:\n State:\t\tcompleted\n Started:\t3 minutes ago\n Completed:\t48 seconds ago\n Message:\tupdate completed\nPlacement:\nUpdateConfig:\n Parallelism:\t1\n Delay:\t\t10s\n On failure:\tpause\nContainerSpec:\n Image:\t\tdarek/goweb:2.0\nResources:\nPorts:\n Protocol = tcp\n TargetPort = 8080\n PublishedPort = 8080\n```\n\nAfter the update, you can verify that the version is really 2.0 with the httpie command. \nLet's now delete the service. \n\n```bash\ndocker service rm web\n```\n\nAnd shutdown the shop for good: `vagrant destroy --force`. \n\n# License \n\nMIT\n\n# Author \nInspired by `denverdino/docker-swarm-mode-vagrant` and `lowescott/learning-tools` repos. \n\nDariusz Dwornikowski @tdi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdi%2Fvagrant-docker-swarm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdi%2Fvagrant-docker-swarm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdi%2Fvagrant-docker-swarm/lists"}