-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New provider: Docker #3347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New provider: Docker #3347
Conversation
|
Oh, and here's the Vagrantfile I've been trying things out: # Force the provider so we don't have to type in --provider=docker all the time
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "dummy"
config.vm.box_url = "http://bit.ly/vagrant-docker-dummy"
config.vm.provider :docker do |docker|
docker.image = 'fgrehm/vagrant-ubuntu:precise'
end
config.vm.define :vm1 do |node|
node.vm.network "forwarded_port", guest: 80, host: 8080
node.vm.provider :docker do |docker|
docker.privileged = true
end
node.vm.synced_folder '.', '/vagrant', id: 'vagrant-root',
type: :nfs,
mount_options:['rw', 'vers=3', 'tcp', 'nolock']
end
config.vm.define :vm2
config.vm.provision :shell, inline: 'apt-get update && apt-get install -y nginx && sudo service nginx start'
end |
|
This only runs on UNIX-like hosts, right? |
|
Yup! |
|
awesome! |
|
@fgrehm Sorry I rebased vagrant-next against master, can you rebase your changes? |
|
@mitchellh done! |
|
Awesome. Let's bring it in. There are quite a few things I want to polish up that I'll email you about, but this is a fantastic start. |
|
Is there any documentation that describes requirements for a docker image that can be run as a provider? I would like to see an example Dockerfile that exposes ports, etc. and configures itself to be accessible and useful when run by the docker-provider. |
|
@rvangundy Any and all docker images |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to create a docker machine with a static IP address --- would it require patching this create method?
This is the code from the docker-provider project, updated to work with Vagrant 1.5 new features and with support for Docker 0.9+ only.
Here's what I installed on my Ubuntu 13.10 machine:
Here are the relevant sections from
docker-providerREADME for future documentation and ideas for what do to next.Features
up,destroy,halt,reloadandsshcommandsInitial setup
The plugin requires Docker's executable to be available on current user's
PATHand that the current user has been added to thedockergroup since we are not usingsudowhen interacting with Docker's CLI. For more information on setting this up please check this page.vagrant upOn its current state, the plugin is not "user friendly" and won't provide any kind of feedback about the process of downloading Docker images, so before you add a
docker-providerbase box it is recommended that youdocker pullthe associated base box images prior to spinning updocker-providercontainers (otherwise you'll be staring at a blinking cursor without any progress information for a while).Under the hood, that base box will configure
docker-providerto use thefgrehm/vagrant-ubuntu:preciseimage that approximates a standard Vagrant box (vagrantuser, default SSH key, etc.) and you should be good to go.Using custom images
If you want to use a custom Docker image without creating a Vagrant base box, you can use a "dummy" box and configure things from your
Vagrantfilelike in vagrant-digitalocean or vagrant-aws:Configuration
This provider exposes a few provider-specific configuration options that are passed on to
docker rununder the hood when the container is being created:image- Docker image to run (required)privileged- Give extended privileges to the container (defaults to false)cmd- An array of strings that makes up for the command to run the container (defaults to what has been set on yourDockerfileasCMDorENTRYPOINT)ports- An array of strings that makes up for the mapped network portsvolumes- An array of strings that makes up for the data volumes used by the containerThese can be set like typical provider-specific configuration:
Networks
Networking features in the form of
config.vm.networkare not supported withdocker-providerapart from forwarded ports. If any of:private_networkor:public_networkare specified, Vagrant won't emit a warning.The same applies to changes on forwarded ports after the container has been created, Vagrant won't emit a warning to let you know that the ports specified on your
Vagrantfilediffers from what has been passed on todocker runwhen creating the container.At some point the plugin will emit warnings on the scenarios described above, but not on its current state. Pull Requests are encouraged ;)
Synced Folders
There is support for synced folders on the form of Docker volumes but as with forwarded ports, you won't be able to change them after the container has been created. NFS synced folders are also supported (as long as you set the
privilegedconfig to true so thatdocker-providercan mount it on the guest container) and are capable of being reconfigured betweenvagrant reloads (different from Docker volumes).This is good enough for all built-in Vagrant provisioners (shell, chef, and puppet) to work!
At some point the plugin will emit warnings when the configured
Vagrantfilesynced folders / volumes differs from the ones used upon the container creation, but not on its current state. Pull Requests are encouraged ;)Box format
The box format is basically just the required
metadata.jsonfile along with aVagrantfilethat does default settings for the provider-specific configuration for this provider.Available base boxes
/sbin/initLimitations
As explained on the networks and synced folder sections above, there are some "gotchas" when using the plugin that you need to have in mind before you start to pull your hair out.
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. As an example, if you change your Puppet manifests / Chef cookbooks paths (which are shared / synced folders under the hood), you'll need to start from scratch (unless you make them NFS shared folders). This is due to a limitation in Docker itself as we can't change those parametersafter the container has been created.