Coder Social home page Coder Social logo

lisa15-docker-tutorial's Introduction

Docker tutorial packer and Vagrant templates

Table of Contents

  1. Overview
  2. Setting up the Tutorial Environment
  1. Performing Tutorial Tasks
  1. IP Addresses and Interfaces
  2. Software Installed
  3. VM Specific Software
  4. Acknowledgements

Overview

Overview goes here.

Setting up the tutorial environment

Requirements

  1. Operating system: Linux, Mac OS X, Windows
  2. Vagrant: version >1.6.2
  3. Packer: if you wish to build the Vagrant box yourself
  4. 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
  1. Network bandwidth: If you do decide to build the box yourself, you can expect to have to download approximately 2.5GB of data
  2. Disk space: for Libvirt you will need approx 6GB under ~/.vagrant.d/boxes and 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.

Building the Vagrant box

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

Providers

Libvirt
packer build ubuntu14.04-dockertutorial.json

IMPORTANT: 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.json
VirtualBox:
packer build vbox-ubuntu14.04-dockertutorial.json
VMWare Fusion (Mac OS X):
packer build vmware-ubuntu14.04-dockertutorial.json

Adding a user

As 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.json

Adding the box to Vagrant

Packer 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'

Provision the virtual machines with Vagrant

Libvirt:

First, ensure you have the vagrant-libvirt plugin installed (vagrant install vagrant-libvirt). Then run the following:

vagrant up --provider=libvirt --no-parallel

Virtualbox:

Run:

vagrant up --provider=virtualbox --no-parallel

VMWare Fusion:

Ensure you have purchased and installed the VMware Fusion Vagrant plugin installed. Run:

export VAGRANT_DEFAULT_PROVIDER=vmware_fusion
vagrant up --no-parallel

Performing tutorial tasks

Build the helloweather Docker image:

First, SSH to dockertutorial-01:

vagrant ssh dockertutorial-01

Then 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.yml

Launch an instance of the container

vagrant@dockertutorial-01:/vagrant$ ansible-playbook ansible_build_deploy/deploy_helloweather.yml

This will deploy the helloweather application on the second virtual machine, dockertutorial-02, by default.

Access the application

Visit http://192.168.123.140:10000 to access the application via the HAProxy load balancer.

Review the HAProxy configuration

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

Launch an additional container

vagrant@dockertutorial-01:/vagrant$ ansible-playbook ansible_build_deploy/deploy_helloweather.yml

Optional: Specify the Shipyard engine (Docker host) you wish to deploy the container to

You 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"

List services registered in Consul

Obtain a list of all services:

curl http://192.168.123.140:8500/v1/catalog/services | json_pp

List details of the helloweather service:

curl http://192.168.123.140:8500/v1/catalog/service/helloweather | json_pp

IP addresses and Interfaces:

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

Software installed:

Check scripts/packages.sh:

  • ansible
  • docker
  • url
  • emacs24-nox
  • htop
  • nmon
  • slurm
  • tcpdump
  • unzip
  • vim-nox

vm specific software:

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

Acknowledgements

The packer setup is largely based on the excellent work of Jacob Adams: packer-qemu-templates

lisa15-docker-tutorial's People

Contributors

pythianliappis avatar bfraser avatar hbombonato avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.