Table of Contents generated with DocToc
Spins up a Docker Swarm mode cluster within a Vagrant environment and uses Ansible to provision the whole environment.
This environment will consist of the following:
I have also included a [Python] script docker-management.py
that will be
worked on over time to do some initial various things but will have more
functionality over time.
Easily spin up the Vagrant environment.
vagrant up
Once everything provisions you are now ready to begin using your Docker Swarm mode cluster.
Connect to one of the Docker Swarm Managers to begin creating services and etc.
vagrant ssh node0
Validate that the Docker Swarm cluster is functional:
docker node ls
You should something similar to below:
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
4y83hx5ywpkn65tp268huipyz * node0 Ready Active Leader
60qm8mohj517vovv7id5p7l6s node2 Ready Active Reachable
cwnkijv7f8gzsvwltnomgmmea node1 Ready Active Reachable
Create a new Docker service:
docker service create --name web --publish 8080:80 --replicas 1 mrlesmithjr/nginx
List the current Docker services:
docker service ls
...
ID NAME REPLICAS IMAGE COMMAND
016psrb2tb7y web 1/1 mrlesmithjr/nginx
List the tasks of a service:
docker service ps web
...
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
9n3yq6k2ig71kkldzrs2zfqb3 web.1 mrlesmithjr/nginx node0 Running Running about a minute ago
Scale the service to increase the number of replicas:
docker service scale web=3
...
web scaled to 3
Now list the current Docker services:
docker service ls
...
ID NAME REPLICAS IMAGE COMMAND
016psrb2tb7y web 3/3 mrlesmithjr/nginx
Now list the tasks of the service:
docker service ps web
...
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
9n3yq6k2ig71kkldzrs2zfqb3 web.1 mrlesmithjr/nginx node0 Running Running 5 minutes ago
bisd4qcaxsx66u6zeuomykkr3 web.2 mrlesmithjr/nginx node1 Running Running 41 seconds ago
8u940el4iomekvsfkqvpz75ox web.3 mrlesmithjr/nginx node2 Running Running 43 seconds ago
Now go and enjoy your Docker Swarm mode cluster and do some learning.
BSD
Larry Smith Jr.
- @mrlesmithjr
- EverythingShouldBeVirtual
- mrlesmithjr
- mrlesmithjr [at] gmail.com