- Requirements
- Building the Vagrant Box
- Adding the Box to Vagrant
- Provision the Virtual Machines With Vagrant
- Build the
helloweatherDocker Image - Launch an Instance of the Container
- Access the Application
- Review the HAProxy Configuration
- Launch an Additional Container
Overview goes here.
- Operating system: Linux, Mac OS X, Windows
- Vagrant: version >1.6.2
- Packer: if you wish to build the Vagrant box yourself
- Vagrant and Packer compatible virtualization tool. Choices include:
- VirtualBox: works on each of the listed operating systems
- KVM + libvirt: for Linux systems. Check installation instructions for your distribution. You will also need the vagrant-libvirt plugin
- VMware Fusion: for Mac systems, also requires the Vagrant VMware plugin. Both of these must be purchased
- Network bandwidth: If you do decide to build the box yourself, you can expect to have to download approximately 2.5GB of data
- Disk space: for Libvirt you will need approx 6GB under
~/.vagrant.d/boxesand the same under/var/lib/libvirt/images(this is due to vagrant-libvirt and how images are stored in libvirt). For the other hypervisors, you will need half of this space.
NOTE: This step is only necessary if you would like to build the box yourself. If you simply want to get started with the tutorial environment, download and add a pre-built box from Atlas for your preferred virtualization provider, or skip to the provisioning step and let Vagrant do it for you.
https://atlas.hashicorp.com/bfraser/boxes/dockertutorial
packer build ubuntu14.04-dockertutorial.jsonIMPORTANT: Libvirt by default uses /tmp during image build operations. If your /tmp is <6GB please provide a directory with sufficient space in the TMPDIR environment variable
export TMPDIR=/path/with/space; packer build ubuntu14.04-dockertutorial.jsonpacker build vbox-ubuntu14.04-dockertutorial.jsonpacker build vmware-ubuntu14.04-dockertutorial.jsonAs an option if you want to create a new user e.g. ubuntu use:
read -p 'Enter password: ' -s password
packer build -var 'user=ubuntu' -var "password=$password" ubuntu14.04-dockertutorial.jsonPacker will build a box that you can find in the box/ directory. Add it to your Vagrant environment using the following command, replacing <provider> with the name of the provider you are using:
vagrant box add box/dockertutorial-<provider>.box --name "dockertutorial"NOTE: If you are manually building the box with Packer and adding it to Vagrant, instead of using one of the pre-built boxes, modify the host_config.vm.box line in Vagrantfile so it reads as follows:
host_config.vm.box = 'dockertutorial'
First, ensure you have the vagrant-libvirt plugin installed (vagrant install vagrant-libvirt). Then run the following:
vagrant up --provider=libvirt --no-parallelRun:
vagrant up --provider=virtualbox --no-parallelEnsure you have purchased and installed the VMware Fusion Vagrant plugin installed. Run:
export VAGRANT_DEFAULT_PROVIDER=vmware_fusion
vagrant up --no-parallelFirst, SSH to dockertutorial-01:
vagrant ssh dockertutorial-01Then change to the /vagrant directory and build the image:
vagrant@dockertutorial-01:~$ cd /vagrant
vagrant@dockertutorial-01:/vagrant$ ansible-playbook ansible_build_deploy/build_helloweather.ymlvagrant@dockertutorial-01:/vagrant$ ansible-playbook ansible_build_deploy/deploy_helloweather.ymlThis will deploy the helloweather application on the second virtual machine, dockertutorial-02, by default.
Visit http://192.168.123.140:10000 to access the application via the HAProxy load balancer.
All helloweather containers automatically get added to the list of HAProxy backends via consul-template. Review the HAProxy configuration which can be found in /etc/haproxy/haproxy.cfg
vagrant@dockertutorial-01:/vagrant$ ansible-playbook ansible_build_deploy/deploy_helloweather.ymlYou may explicitly specify the Shipyard engine (Docker host) you wish your container to land on by overriding the variable target_shipyard_engine. For example, to deploy the helloweather application to dockertutorial-03, you'd run:
vagrant@dockertutorial-01:/vagrant$ ansible-playbook ansible_build_deploy/deploy_helloweather.yml -e "target_shipyard_engine=dockertutorial-03"Obtain a list of all services:
curl http://192.168.123.140:8500/v1/catalog/services | json_ppList details of the helloweather service:
curl http://192.168.123.140:8500/v1/catalog/service/helloweather | json_pp| Vagrant VM name | IP Address | Consul | Shipyard | HAProxy |
|---|---|---|---|---|
| dockertutorial-01 | 192.168.123.140 | http://192.168.123.140:8500 | http://192.168.123.140:8080 | http://192.168.123.140:10000 |
| dockertutorial-02 | 192.168.123.141 | http://192.168.123.141:8500 | ||
| dockertutorial-03 | 192.168.123.142 | http://192.168.123.142:8500 |
Check scripts/packages.sh:
- ansible
- docker
- url
- emacs24-nox
- htop
- nmon
- slurm
- tcpdump
- unzip
- vim-nox
| Vagrant VM name | Software installed |
|---|---|
| dockertutorial-01 | docker |
| shipyard | |
| packer | |
| ansible | |
| docker private registry:2 | |
| consul server agent | |
| registrator | |
| consul-template |
| Vagrant VM name | Software installed |
|---|---|
| dockertutorial-02 | docker |
| packer | |
| ansible | |
| consul server agent | |
| registrator | |
| consul-template |
| Vagrant VM name | Software installed |
|---|---|
| dockertutorial-03 | docker |
| packer | |
| ansible | |
| consul server agent | |
| registrator | |
| consul-template |
The packer setup is largely based on the excellent work of Jacob Adams: packer-qemu-templates