Skip to content

Instantly share code, notes, and snippets.

@tuxpower
Created August 22, 2016 18:56
Show Gist options
  • Save tuxpower/3b229521206096c36284e371d79219e2 to your computer and use it in GitHub Desktop.
Save tuxpower/3b229521206096c36284e371d79219e2 to your computer and use it in GitHub Desktop.
Docker - Getting started with swam
$ docker-machine create -d virtualbox node1
$ docker-machine create -d virtualbox node2
$ docker swarm init --advertise-addr 192.168.99.100
Swarm initialized: current node (3e9deoyqmm4q95xmxegtlusi0) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-05ii9ckfw8evswg3spzgtef8pvy9l2e1izzp16k0gxtwchr96u-b7q7ksfqdum2jrybdsb9qobrx \
192.168.99.100:2377
To add a manager to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-05ii9ckfw8evswg3spzgtef8pvy9l2e1izzp16k0gxtwchr96u-4wj3loqymvs5asglru8c72fuz \
192.168.99.100:2377
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
2dsuoxyxv7ra425vi563yck50 node2 Ready Active
3e9deoyqmm4q95xmxegtlusi0 * node1 Ready Active Leader
$ docker network create -d overlay skynet
byts2wtg8y6twa1cv3o9ae5op
$ docker service create --name http --network skynet --replicas 2 -p 80:80 katacoda/docker-http-server
3m73t32l3yn4xg8bewokacrxp
$ docker service ls
ID NAME REPLICAS IMAGE COMMAND
3m73t32l3yn4 http 0/2 katacoda/docker-http-server
$ docker service ls
ID NAME REPLICAS IMAGE COMMAND
3m73t32l3yn4 http 2/2 katacoda/docker-http-server
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e85e1ff57b04 katacoda/docker-http-server:latest "/app" 33 seconds ago Up 32 seconds 80/tcp http.1.82h7ksctorx498vztr8fh4896
$ curl 192.168.99.100
<h1>This request was processed by host: 708e6bc40c55</h1>
$ docker service ps http
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
82h7ksctorx498vztr8fh4896 http.1 katacoda/docker-http-server node1 Running Running 5 minutes ago
537hlv2qff8p7v9ovqvfgj3go http.2 katacoda/docker-http-server node2 Running Running 5 minutes ago
$ docker node ps self
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
82h7ksctorx498vztr8fh4896 http.1 katacoda/docker-http-server node1 Running Running 6 minutes ago
$ docker node ps $(docker node ls -q | head -n1)
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
537hlv2qff8p7v9ovqvfgj3go http.2 katacoda/docker-http-server node2 Running Running 7 minutes ago
$ docker node ls -q
2dsuoxyxv7ra425vi563yck50
3e9deoyqmm4q95xmxegtlusi0
$ docker service scale http=4
http scaled to 4
$ docker service ps http
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
82h7ksctorx498vztr8fh4896 http.1 katacoda/docker-http-server node1 Running Running 9 minutes ago
537hlv2qff8p7v9ovqvfgj3go http.2 katacoda/docker-http-server node2 Running Running 9 minutes ago
dzxexyx8mv2aox2frg8y4jt45 http.3 katacoda/docker-http-server node2 Running Running 10 seconds ago
62dj0w5v0x02mpjvztdss7i4a http.4 katacoda/docker-http-server node1 Running Running 10 seconds ago
$ curl 192.168.99.100
<h1>This request was processed by host: 4f8485aef449</h1>
$ curl 192.168.99.100
<h1>This request was processed by host: 15159e131712</h1>
$ curl 192.168.99.100
<h1>This request was processed by host: 708e6bc40c55</h1>
$ curl 192.168.99.100
<h1>This request was processed by host: e85e1ff57b04</h1>
$ curl 192.168.99.100
<h1>This request was processed by host: 4f8485aef449</h1>
#################################################################################################
NODE 2
#################################################################################################
$ token=$(docker -H 192.168.99.100:2376 swarm join-token -q worker)
$ docker swarm join 192.168.99.100:2377 --token $token
This node joined a swarm as a worker.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
708e6bc40c55 katacoda/docker-http-server:latest "/app" 50 seconds ago Up 50 seconds 80/tcp http.2.537hlv2qff8p7v9ovqvfgj3go
$ curl 192.168.99.100
<h1>This request was processed by host: e85e1ff57b04</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment