Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active December 23, 2015 23:16
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dergachev/5824851 to your computer and use it in GitHub Desktop.
Save dergachev/5824851 to your computer and use it in GitHub Desktop.
Experimenting with vagrant-lxc and docker

Trying Vagrant / LXC / Docker

LXC

Here are some LXC links:

To play around with lxc, I did the following (inside an Ubuntu VM, since lxc only works with linux)

sudo apt-get install lxc -y
sudo lxc-create -t ubuntu -n my-container    # downloads 400+MB of packages the first time, then caches

# opens a login shell to the container (user/pass: ubuntu/ubuntu; to exit the shell, you need to run "sudo halt" inside the container; also consider using screen)
lxc-start -n my-container  
# if you don't feel like using screen, this starts the container in the background
lxc-start -n my-container -d
lxc-console -n my-container # like lxc-ssh but without ssh; only useful if you did "lxc-start -d"
lxc-ssh -n my-container  # like vagrant ssh
lxc-console -n my-container # like lxc-ssh but without ssh
lxc-list
lxc-info -n my-container
ps aux   # notice that all lxc container processes are visible from the host
sudo lxc-destroy -n my-container    # kills the container
ls /var/lib/lxc/my-container/rootfs # contains the root filesystem of the container
ls /var/cache/lxc/ # contains 400+ MB of cached packages, etc
# you can type lxc-[TAB][TAB] to see all lxc commands

LXC resources:

Now I'm interested in seeing the advantages of using vagrant-lxc instead of vagrant and virtualbox. Although it's not cross-platform, it's quicker to setup, supposedly more light-weight, and shouldn't suffer the slowness of Virtualbox shared folders. To give it a go (once again, inside a virtualbox VM):

wget http://files.vagrantup.com/packages/7e400d00a3c5a0fdf2809c8b5001a035415a607b/vagrant_1.2.2_x86_64.deb
sudo dpkg -i vagrant_1.2.2_x86_64.deb
vagrant plugin install vagrant-lxc
sudo apt-get install -y lxc redir
vagrant box add precise64-lxc http://dl.dropbox.com/u/13510779/lxc-precise-amd64-2013-05-08.box
vagrant init precise64-lxc
vagrant up --provider=lxc     # works, takes ~ 5 seconds
vagrant halt                        # works!
touch testfile.txt                  # create a file in Vagrant project root
vagrant ssh -- 'ls /vagrant/'   # it's shared in the VM

Docker

This section is incomplete.

apt-get install linux-image-extra-$(uname -r)   ### FAILED to find package "...-generic", guess not necessary in virtualbox
apt-get install software-properties-common
add-apt-repository ppa:dotcloud/lxc-docker 
apt-get update
apt-get install lxc-docker

docker
docker info
docker pull base
docker run -i -t base /bin/bash
docker info

debootstrap precise ./bootstrap
vim /home/vagrant/bootstrap/var/cache/apt/archives/gcc-4.6-base_4.6.3-1ubuntu5_amd64.deb
tar -C / -c . | docker import - entend/custombase

Because files.travis-ci.org/boxex/ are all 32-bit (out of date with prod, can't run docker), I need to build my own:

git clone https://github.com/travis-ci/travis-boxes.git
git clone https://github.com/travis-ci/travis-cookbooks.git
sudo apt-get install libxslt-dev libxml2-dev
cd travis-boxes
bundle install 

# vagrant / virtualbox version error workaround

Docker resources:

@bmullan
Copy link

bmullan commented Dec 23, 2015

Stephane Graber is one of the lead LXC developers and he has a terrific 10 part Blog post - https://www.stgraber.org/2013/12/20/lxc-1-0-blog-post-series/ Can't recommend it enough. It is from 2014 but still hits most of the highlights.

The LXC website has all the information, sw, guides etc you might need for LXC, LXD & related projects - www.linuxcontainers.org

The upcoming first release of LXD will greatly enhance LXC with its REST interface capability allowing you to deploy & manage LXC containers on any Host you have access to. It also will, with the LXC v2.0 release (scheduled for around Jan 16th), add LXC container migration w/CRIU, local/remote LXC container mgmt (create, start/stop/pause/delete etc).

Flockport also has done a good job creating perhaps 40 guides related to various LXC related configuration or use-case's - https://www.flockport.com/guides/

its worth noting that Canonical's awesome Juju environment supports LXC as 1 of multiple "environments". This lets you use either the Juju CLI or its GUI to deploy & manage any of the extensive Juju "Charms" ie applications into LXC containers if you want.

There is now an LXD plugin called NCLXD for OpenStack Neutron allowing OpenStack to orchestrate LXC containers instead of hw VMs. From what I understand Canonical's goal for Ubuntu 16.04 LTS release is to enable deployment of both OpenStack & the payloads (re VMs) OpenStack managers for you all running in LXC by using the LXD/LXC REST api for the control-plane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment