Edit YAML data files to use nested data structures. Edit Vagrantfile to reference YAML data accordingly. Signed-off-by: Scott S. Lowe <scott.lowe@scottlowe.org> |
||
|---|---|---|
| .. | ||
| ansible.cfg | ||
| machines.yml | ||
| provision.yml | ||
| README.md | ||
| Vagrantfile | ||
Running LXC-Based OS Containers with LXD
These files were created to allow users to use Vagrant (http://www.vagrantup.com) and Ansible (http://www.ansible.com) to relatively easily experiment with LXD (pronounced "lex-dee"), a new daemon and CLI client for working with LXC-based OS containers. The configuration was tested using Vagrant 1.8.1, VMware Fusion 8.1.0, the Vagrant VMware plugin, and Ansible 1.9.1. Other versions are likely to work, but haven't been tested.
Contents
-
ansible.cfg: This Ansible configuration file instructs Ansible to use an inventory file named
hostsin the current directory, and to use the default vagrant user (vagrant) and default insecure Vagrant SSH private key. -
hosts: This file is created automatically when you run
vagrant statusorvagrant up(anytime Vagrant processesVagrantfile). This file relies on the presence of a "ip_addr" value inmachines.yml. Do not edit this file directly---instead editmachines.ymlto change the values that will be automatically written into this file. -
machines.yml: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by
Vagrantfilewhen Vagrant instantiates the VMs. Only minimal changes may be needed to this file; see the "Instructions" section below. -
provision.yml: This YAML file is an Ansible playbook that configures the VMs created by Vagrant when they are first provisioned. Ansible is called automatically by Vagrant; you do not need to invoke Ansible separately. No changes are needed to this file.
-
README.md: The file you're currently reading.
-
Vagrantfile: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file.
Instructions
These instructions assume you've already installed VMware Fusion, Vagrant, the Vagrant VMware plugin, and Ansible. Please refer to the documentation for those products for more information on installation or configuration.
-
Use
vagrant box addto install an Ubuntu 14.04 x64 box for the "vmware_fusion" provider. I have a base box you can use for this purpose; to use my Ubuntu 14.04 x64 base box, add the box withvagrant box add slowe/ubuntu-trusty-x64. (In theory you should be able to use this Vagrant environment with VMware Workstation as well, but only VMware Fusion was tested.) -
Place the files from the
lxddirectory of this GitHub repository (the "lowescott/learning-tools" repository) into a directory on your system. You can clone the entire "learning-tools" repository (usinggit clone), or just download the specific files from thelxddirectory. -
Edit
machines.ymlto ensure that the box specified in that file matches the Ubuntu 14.04 x64 base box you just installed and will be using. I recommend that you do not change any other values in this file unless you know it is necessary. If you use my base box as described in step #1, no changes are needed tomachines.yml. -
From a terminal window, change into the directory where the files from this directory are stored and run
vagrant upto bring up the VMs specified inmachines.ymlandVagrantfile. (By default, it will create and power on only a single VM.) -
Once Vagrant has finished creating, booting, and provisioning the VM (note you'll need Internet access for this step), log into the VM (named "lxd-01" by default) using
vagrant ssh. -
Add the public LinuxContainers.org image repository by running
lxc remote add lxc-org images.linuxcontainers.org. -
Copy the 32-bit Ubuntu 14.04 container image to your system with the command
lxc image copy lxc-org:/ubuntu/trusty/i386 local: --alias=trusty32. -
Launch a container based on this image with the command
lxc launch trusty32 lxd-test-01. This will start a container named "lxd-test-01" based on the "trusty32" image (which is an alias for the image you copied in step 7). -
Run
file /bin/lsand note the output. (You'll use the output for comparison in just a moment.) -
Open a shell in the 32-bit container you launched in step 8 with the command
lxc exec lxd-test-01 /bin/bash. -
Inside the container, run
file /bin/lsand compare the output to the output of the same command you ran outside the container. You'll see that inside the container the file is reported as a 32-bit ELF executable; outside the container the same file is listed as a 64-bit ELF executable. -
Press Ctrl-D to exit the shell in the container.
-
The container is still running, so stop the container with
lxc stop lxd-test-01.
There you have it---a way to quickly and easily experiment with LXD. Enjoy!