Question

I have the following Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

$script = <<SCRIPT
  apt-get install -y mongodb
  mongo dummydb -u admin -p admin --eval "db.addUser('dummyuser', 'dummypass')"
SCRIPT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64_vmware_fusion.box"

  # MongoDB ports
  config.vm.network "forwarded_port", guest: 27017, host: 27017

  # RabbitMQ ports
  config.vm.network "forwarded_port", guest: 5672, host: 5672
  config.vm.network "forwarded_port", guest: 55672, host: 55672

  config.vm.provision "docker" do |docker|
    docker.run "tutum/mongodb", daemonize: true, args: "-p 27017:27017 -e MONGODB_PASS=\"admin\""
    docker.run "tutum/rabbitmq", daemonize: true, args: "-p 5672:5672 -p 55672:55672 -e RABBITMQ_PASS=\"admin\""
  end

  # config.vm.provision "shell", inline: $script
end

When I run this using

$ vagrant up --provider=vmware_fusion

this works perfectly: The virtual machine is created, Docker is installed and MongoDB as well as RabbitMQ are set up and the password is assigned accordingly. So far, everything's fine.

When I now uncomment the last line which executes the shell provisioner (which, according to the documentation, should work like this), I get a really strange error: Vagrant installs Docker, pulls the tutum/mongodb image and then tells me that running the container failed:

==> default: Starting Docker containers...
==> default: -- Container: tutum/mongodb
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

          rm -f /var/lib/vagrant/cids/1bef9ddec8969e37432fbe8c55f6d9452cd61e4a
          docker run -cidfile=/var/lib/vagrant/cids/1bef9ddec8969e37432fbe8c55f6d9452cd61e4a -d -name tutum/mongodb -p 27017:27017 -e MONGODB_PASS="admin" tutum/mongodb 

Stdout from the command:

Stderr from the command:

stdin: is not a tty
Warning: '-cidfile' is deprecated, it will be replaced by '--cidfile' soon. See usage.
Warning: '-name' is deprecated, it will be replaced by '--name' soon. See usage.
Unable to find image 'tutum/mongodb' locally
Pulling repository tutum/mongodb

2014/03/27 01:31:40 Error: Invalid container name (tutum/mongodb), only [a-zA-Z0-9_.-] are allowed

I guess the problem is the parameter -name tutum/mongodb that Vagrant automatically applies to the docker run call.

What I do not understand is why this happens only if I add the shell provisioner (which obviously has nothing to do with setting up Docker or Docker containers).

Does anybody have an idea why this is?

I am using Vagrant 1.5.1, the Vagrant VMWare Fusion provider 2.3.4, and VMWare 6.0.2, all on OS X 10.9.2.

Does anybody have an idea what might cause this issue, and how to solve it?

PS: My current workaround is to apply auto_assign_name: false within the Vagrantfile, but this is only a workaround. I'm curious what the actual problem is and how to solve it correctly.

Was it helpful?

Solution

Docker is complaining because of the single - instead of the double -- . check the docs for the new way to specify them.

To successfully run the command use

docker run --cidfile=/var/lib/vagrant/cids/1bef9ddec8969e37432fbe8c55f6d9452cd61e4a -d --name="tutum/mongodb" -p 27017:27017 -e MONGODB_PASS="admin" tutum/mongodb

But solving that in vagrant would require a core provisioner code update.

Update

This has been fixed in version 1.5.2, looking at this commit seems that they're using --name and --cidfile now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top