docker-provider
A spike on a Docker provider for Vagrant 1.3+.
Warning
This is highly experimental and is just 8 tomatoes worth of development / testing.
Requirements
- Vagrant 1.3+
- Docker 0.6.5+
Features
- Support for Vagrant's
up,destroy,halt,reloadandsshcommands - Port forwarding
- Synced / shared folders support
- Set container hostnames from Vagrantfiles
- Provision Docker containers with any built-in Vagrant provider
Getting started
If you are on a Mac / Windows machine, please fire up a x64 VM with Docker + Vagrant installed or use this Vagrantfile and follow the instructions from there.
The plugin is not very user friendly at the moment, so please download the base
Docker image manually with docker pull fgrehm/vagrant-ubuntu:precise in order
to have some feedback about the download process.
Assuming you have Vagrant 1.3+ and Docker 0.6.5+ installed just sing that same old song:
vagrant plugin install docker-provider
vagrant box add precise http://bit.ly/vagrant-docker-precise
vagrant init precise
vagrant up --provider=docker
Using custom images
If you want to use a custom Docker image without creating a Vagrant base box, you can use a "dummy" box:
vagrant box add dummy http://bit.ly/vagrant-docker-dummy
And configure things from your Vagrantfile like in vagrant-digitalocean
or vagrant-aws:
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.provider :docker do |docker|
docker.image = "your/image:tag"
docker.cmd = ["/path/to/your", "command"]
end
end
Limitations
There's probably a whole lot of limitations right now but during these early days
of the plugin I can tell you for sure that some things are probably not going to
work as you might expect. For instance forwarded ports, synced folders and containers'
hostnames will not be reconfigured on vagrant reloads if they have changed and
the plugin will not give you any kind of warning or message. Forwarded ports
automatic collision handling is not supported as well.
The plugin also requires Docker's executable to be available on current user's PATH
and that the current user has been added to the docker group since we are not
using sudo when interacting with Docker's CLI. For more information on setting
this up please check this page.
Another thing to keep in mind is that Docker is all about application containers
and not machine containers. I failed to boot a Docker container in what people
have been calling "machine mode"
and some hacking will be required in order to run multiple processes on the
container as described below. For more information about the issues related to
it, please search Docker's issue tracker for /sbin/init and / or "machine mode".
Box format
Every provider in Vagrant must introduce a custom box format. This provider introduces
docker boxes and you can view some examples in the boxes directory.
That directory also contains instructions on how to build them.
The box format is basically just the required metadata.json file along with a
Vagrantfile that does default settings for the provider-specific configuration
for this provider.
Running multiple processes on the container
Unless you are able to run the container in "machine mode", you'll need to create
a custom command / script that starts the processes you need prior to firing up
the SSH server. An example can be found at the boxes/nginx
folder of this repo.
On a side note, if you really need your Docker containers to behave like machines with Vagrant and you can't get it to work that way like me, you might want to use vagrant-lxc as an alternative.
Got feedback?
Please keep in mind that this is a spike and I'm not sure if / how the project will evolve. I'm planning to write about why I built this at some point but in case you have any feedback feel free to open up an issue here on GitHub, shoot a tweet to @fgrehm or send a mail to the address available on my GitHub profile.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
