Merge pull request #2585 from mitchellh/2585-fix-docker-image-assignment

provisioner/docker: unable to run multiple docker containers based off the same image
This commit is contained in:
Mitchell Hashimoto 2013-12-06 14:56:15 -08:00
commit 89f4e14ab3
2 changed files with 17 additions and 5 deletions

View File

@ -22,7 +22,7 @@ module VagrantPlugins
def run(name, **options) def run(name, **options)
params = options.dup params = options.dup
params[:image] = name params[:image] ||= name
# TODO: Validate provided parameters before assignment # TODO: Validate provided parameters before assignment
@containers[name.to_s] = params @containers[name.to_s] = params

View File

@ -92,11 +92,11 @@ to the name, the `run` method accepts a set of options, all optional:
but can also be given here as an option. but can also be given here as an option.
* `cmd` (string) - The command to start within the container. If not specified, * `cmd` (string) - The command to start within the container. If not specified,
then the containers default "run" command will be used, such as the then the container's default "run" command will be used, such as the
"run" command specified when the container was built. "run" command [specified on the `Dockerfile`](http://docs.docker.io/en/latest/use/builder/#run).
* `args` (string) - Extra arguments for `docker run` on the command line. * `args` (string) - Extra arguments for [`docker run`](http://docs.docker.io/en/latest/commandline/cli/#run)
These are raw arguments that are passed directly to Docker. on the command line. These are raw arguments that are passed directly to Docker.
For example, here is how you would configure Docker to run a container For example, here is how you would configure Docker to run a container
with the Vagrant shared directory mounted inside of it: with the Vagrant shared directory mounted inside of it:
@ -110,3 +110,15 @@ Vagrant.configure("2") do |config|
end end
end end
``` ```
In case you need to run multiple containers based off the same image, you can do
so by providing different names and specifying the `image` parameter to it:
```ruby
Vagrant.configure("2") do |config|
config.vm.provision "docker" do |d|
d.run "db-1", image: "user/mysql"
d.run "db-2", image: "user/mysql"
end
end
```