Created
August 23, 2016 09:23
-
-
Save tuxpower/0a5a45c153c611bf28433680b2d69a89 to your computer and use it in GitHub Desktop.
https://medium.com/@lherrera/solving-the-routing-mess-for-services-in-docker-73492c37b335#.u5b1phz1x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-machine create --driver virtualbox swarm-1 | |
$ docker-machine create --driver virtualbox swarm-2 | |
$ docker-machine create --driver virtualbox swarm-3 | |
$ docker-machine ls | |
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS | |
swarm-1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.1 | |
swarm-2 * virtualbox Running tcp://192.168.99.101:2376 v1.12.1 | |
swarm-3 - virtualbox Running tcp://192.168.99.102:2376 v1.12.1 | |
$ eval $(docker-machine env swarm-1) | |
$ docker swarm init --advertise-addr $(docker-machine ip swarm-1) | |
$ eval $(docker-machine env swarm-2) | |
$ docker swarm join --token SWMTKN-1-1twrnncnm6uktwjeml3e8arbyqr5dydvpqhxqryt2dlt6o0mhj-3amgy4crey8h7c77txfq1gma6 192.168.99.100:2377 | |
This node joined a swarm as a manager. | |
$ eval $(docker-machine env swarm-3) | |
$ docker swarm join --token SWMTKN-1-1twrnncnm6uktwjeml3e8arbyqr5dydvpqhxqryt2dlt6o0mhj-3amgy4crey8h7c77txfq1gma6 192.168.99.100:2377 | |
This node joined a swarm as a manager. | |
$ eval $(docker-machine env swarm-1) | |
$ docker node ls | |
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS | |
25f7jn2fgrm6f0ll4sf2wwsi9 swarm-2 Ready Active Reachable | |
dqkalmhnmksszz6me8xxvfkmn * swarm-1 Ready Active Leader | |
ervcngni33jk2to2vgrli8uxr swarm-3 Ready Active Reachable | |
$ docker network create --driver overlay webnet | |
edqglr0jvsbw7pj30xsp0db1k | |
$ docker service create --name webapp --replicas=3 --network webnet --publish 80:8000 lherrera/webapp:1.0 | |
asg9oh5oc5uxzafn7qamkyraq | |
$ docker service create --name redisdb --network webnet --replicas=1 redis:alpine | |
e4loits93ch2sdh4gqfdf0zom | |
$ docker service ls | |
ID NAME REPLICAS IMAGE COMMAND | |
asg9oh5oc5ux webapp 3/3 lherrera/webapp:1.0 | |
e4loits93ch2 redisdb 1/1 redis:alpine | |
$ docker node ls | |
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS | |
25f7jn2fgrm6f0ll4sf2wwsi9 swarm-2 Ready Active Reachable | |
dqkalmhnmksszz6me8xxvfkmn * swarm-1 Ready Active Leader | |
ervcngni33jk2to2vgrli8uxr swarm-3 Ready Active Reachable | |
$ docker service ps webapp | |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR | |
ajvg8tn8vf1ittgfc3a9ory2i webapp.1 lherrera/webapp:1.0 swarm-1 Running Running 58 seconds ago | |
9tdm8q2mu1hrnm22u0wb2hmqo webapp.2 lherrera/webapp:1.0 swarm-3 Running Running 57 seconds ago | |
0esnbpwk5jwf46u2myhi4cet6 webapp.3 lherrera/webapp:1.0 swarm-2 Running Running 59 seconds ago | |
$ docker service ps redisdb | |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR | |
2hrskx9j2ct2k21zxvcb1m772 redisdb.1 redis:alpine swarm-2 Running Running 52 seconds ago | |
$ docker service inspect webapp --format '{{ .Endpoint.VirtualIPs }}' | |
[{2rvzsdha4ra9ik8p9v11d1mgw 10.255.0.6/16} {edqglr0jvsbw7pj30xsp0db1k 10.0.0.2/24}] | |
$ NODE1=$(docker-machine ip swarm-1) | |
$ curl $NODE1 | |
Hello, I'm version 1.0.My hostname is 6650ce8999ad, this page has been viewed 1 | |
and my ip addresses are 10.255.0.8,10.255.0.6,172.18.0.3,10.0.0.4,10.0.0.2 | |
$ curl $NODE1 | |
Hello, I'm version 1.0.My hostname is 2c274ff6f2ec, this page has been viewed 2 | |
and my ip addresses are 10.255.0.7,10.255.0.6,172.18.0.3,10.0.0.3,10.0.0.2 | |
$ curl $NODE1 | |
Hello, I'm version 1.0.My hostname is 06ec55c917da, this page has been viewed 3 | |
and my ip addresses are 10.255.0.9,10.255.0.6,172.18.0.3,10.0.0.5,10.0.0.2 | |
$ docker service update --update-parallelism 1 --update-delay 5s --image lherrera/webapp:2.0 webapp | |
webapp | |
$ docker service ps webapp | |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR | |
ajvg8tn8vf1ittgfc3a9ory2i webapp.1 lherrera/webapp:1.0 swarm-1 Running Running 13 minutes ago | |
9tdm8q2mu1hrnm22u0wb2hmqo webapp.2 lherrera/webapp:1.0 swarm-3 Running Running 13 minutes ago | |
8q43hzbao4nq3drijh7eo7hfl webapp.3 lherrera/webapp:2.0 swarm-1 Ready Ready 2 seconds ago | |
0esnbpwk5jwf46u2myhi4cet6 \_ webapp.3 lherrera/webapp:1.0 swarm-2 Shutdown Running 13 minutes ago | |
$ docker service ps webapp | |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR | |
ajvg8tn8vf1ittgfc3a9ory2i webapp.1 lherrera/webapp:1.0 swarm-1 Running Running 13 minutes ago | |
9tdm8q2mu1hrnm22u0wb2hmqo webapp.2 lherrera/webapp:1.0 swarm-3 Running Running 13 minutes ago | |
8q43hzbao4nq3drijh7eo7hfl webapp.3 lherrera/webapp:2.0 swarm-1 Ready Ready 4 seconds ago | |
0esnbpwk5jwf46u2myhi4cet6 \_ webapp.3 lherrera/webapp:1.0 swarm-2 Shutdown Running 13 minutes ago | |
$ docker service ps webapp | |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR | |
ajvg8tn8vf1ittgfc3a9ory2i webapp.1 lherrera/webapp:1.0 swarm-1 Running Running 13 minutes ago | |
9tdm8q2mu1hrnm22u0wb2hmqo webapp.2 lherrera/webapp:1.0 swarm-3 Running Running 13 minutes ago | |
8q43hzbao4nq3drijh7eo7hfl webapp.3 lherrera/webapp:2.0 swarm-1 Running Running 3 seconds ago | |
0esnbpwk5jwf46u2myhi4cet6 \_ webapp.3 lherrera/webapp:1.0 swarm-2 Shutdown Shutdown 3 seconds ago | |
$ docker service ps webapp | |
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR | |
ajvg8tn8vf1ittgfc3a9ory2i webapp.1 lherrera/webapp:1.0 swarm-1 Running Running 14 minutes ago | |
6820ms1rhkokgv9ppx74j5byh webapp.2 lherrera/webapp:2.0 swarm-3 Ready Ready 7 seconds ago | |
9tdm8q2mu1hrnm22u0wb2hmqo \_ webapp.2 lherrera/webapp:1.0 swarm-3 Shutdown Running 14 minutes ago | |
8q43hzbao4nq3drijh7eo7hfl webapp.3 lherrera/webapp:2.0 swarm-1 Running Running 14 seconds ago | |
0esnbpwk5jwf46u2myhi4cet6 \_ webapp.3 lherrera/webapp:1.0 swarm-2 Shutdown Shutdown 14 seconds ago | |
$ curl $NODE1 | |
Hello, I'm version 2.0.My hostname is 248e278f183f, this page has been viewed 7 | |
and my ip addresses are 10.255.0.8,10.255.0.6,172.18.0.3,10.0.0.4,10.0.0.2 | |
$ curl $NODE1 | |
Hello, I'm version 2.0.My hostname is 80b3eb7a3018, this page has been viewed 8 | |
and my ip addresses are 10.255.0.10,10.255.0.6,172.18.0.4,10.0.0.8,10.0.0.2 | |
$ curl $NODE1 | |
Hello, I'm version 2.0.My hostname is 248e278f183f, this page has been viewed 9 | |
and my ip addresses are 10.255.0.8,10.255.0.6,172.18.0.3,10.0.0.4,10.0.0.2 | |
$ docker-machine create -d virtualbox swarm-4 | |
$ eval $(docker-machine env swarm-4) | |
$ docker swarm join --token SWMTKN-1-1twrnncnm6uktwjeml3e8arbyqr5dydvpqhxqryt2dlt6o0mhj-90cplgpk1x15tk78yllrs9g25 $(docker-machine ip swarm-1):2377 | |
This node joined a swarm as a worker. | |
$ docker service update --replicas=4 webapp | |
webapp | |
$ docker node ls | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment