Skip to content

tooming/vagrant-ansible-docker-swarm

 
 

Repository files navigation

Table of Contents generated with DocToc

Purpose

Spins up a Docker Swarm mode cluster within a Vagrant environment and uses Ansible to provision the whole environment.

Requirements

Information

This environment will consist of the following:

  • 3 Ubuntu 16.04 nodes
    • 3 Docker Swarm Managers (node0-node2)

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.

Usage

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.

License

BSD

Author Information

Larry Smith Jr.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 65.7%
  • Shell 34.3%