A Vagrant configurations that deploys a Docker swarm using Ansible
- Deploy two CentOs
- Configure the VMs with 50 GB of space
- Deploy Docker on the VMs
- Expose REST API
- configure the API to use tls
- Configure a Docker Swarm, one vm will be the master the other will be the Worker
The VMs are configured using Ansible The code on github uses travis + ansible-lint for CI It is nice to test using Molecule
- Vagrant configuration: six ansible pratices
- Docker installation: ansible-role-docker
- Protect the Docker sockert: docker documentation or the better-formatted secure docker API
- Configure the Docker swarm: Docker swarm doc.
quick how-to
- ansible
- vagrant
- vagrant plugins vagrant-disksize (vagrant hostupdater is reccomended)
I used a config file for ssh to ease the connection to the vms
#For vagrant virtual machines
Host 192.168.33.* *.myapp.dev
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
User root
LogLevel ERROR
This config file will ensure the use of root when connecting throught ssh and ignore ssh host check
The usage consist in creating the virtual machines with
vagrant up
and running the ansible playbook with
ansible-playbook -i hosts playbook.yml
To connect to the swarm using the protected REST API you have to install docker-ce and fire the command:
docker --tlsverify --tlscacert=ca.crt --tlscert=/client.crt --tlskey=/client-key.pem -H={{ HOST }}:2376 node ls
Where the variable HOST is one of the VMs.
the command node ls will return the nodes connected to the swarm