phusion/open-vagrant-boxes

Vagrant executing docker commands fails

Opened this issue · 9 comments

This is the Vagrantfile for my docker host running via VirtualBox:

Vagrant.configure(2) do |config|
  config.vm.box = 'phusion/ubuntu-14.04-amd64'

  config.vm.provider 'virtualbox' do |provider|
    provider.customize ['modifyvm', :id, '--memory', 4096]
    provider.customize ['modifyvm', :id, '--acpi', 'on']
    provider.customize ['modifyvm', :id, '--cpus', 2]
    provider.customize ['modifyvm', :id, '--cpuexecutioncap', '100']
    provider.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
    provider.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
  end

  ['vmware_fusion', 'vmware_workstation'].each do |vmware|
    config.vm.provider vmware do |provider|
      provider.vmx['numvcpus'] = 2
      provider.vmx['memsize'] = 4096
    end
  end

  if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
    pkg_cmd = "wget -q -O - https://get.docker.io/gpg | apt-key add -;" \
      "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list;" \
      "apt-get update -qq; apt-get install -q -y --force-yes lxc-docker; "

    pkg_cmd << "usermod -a -G docker vagrant; "
    config.vm.provision :shell, :inline => pkg_cmd
  end
end

When running this, Vagrant throws this error after Docker was installed on the VM:

A Docker command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.

Command: "docker" "ps" "-a" "-q" "--no-trunc"

Stderr: 2014/06/01 18:10:58 Get http:///var/run/docker.sock/v1.11/containers/json?all=1: dial unix /var/run/docker.sock: permission denied

Stdout:

Any idea why this happens and/or how I can fix it? Thanks a lot!

Okay - it seems like a second vagrant up --provider="docker" executes well. Any idea how I can fix the first run? Do I need a reboot after Docker was installed? Thanks! :)

What are you trying to do? Create a host vm that can be used on non-Linux hosts when using Vagrant's Docker provider? Not sure if that made sence; for more info read the last section in http://docs.vagrantup.com/v2/docker/basics.html

Yes, that's what I'm doing. More about this can also be read here:
http://docs.vagrantup.com/v2/docker/configuration.html using vagrant_vagrantfile.

I'm getting similar errors using VMWare Fusion:

A Docker command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.

Command: "docker" "ps" "-a" "-q" "--no-trunc"

Stderr: bash: line 2: docker: command not found

Stdout:

Trying vagrant up a second time doesn't help. Anybody know what's going on?

See this answer: hashicorp/vagrant#3998 (comment)
The logout / login indeed solves the problem for me.
Also ensure that the user that is running docker belongs to docker group.

@fracz could you maybe post your final working Vagrantfile here or in a gist? I'm experiencing the same problem and couldn't really figure out where to add the login/logout bit...

@dklots, I did not automate this process, I have just rebooted the system (which implies login/logout).

ddmrs commented

Sorry for commenting on an old issue, but was running into this problem now, with 1.7.4.
When using a host vagrantfile for the docker provider and calling the docker provision statement for auto installing docker onto the docker host, it seems that no docker user is created nor is user vagrant given the rights to execute docker commands.
Was able to overcome this issue by declaring ssh.username=root and password, so that docker commands can be run. Which doesn't feel right tbh.

@ddmrs I don't know if this was ever really fixed, but the workaround described here in this comment worked/works for me (it can be used to force vagrant to logout and login again after docker is installed and the docker group added to the vagrant user): hashicorp/vagrant#3998 (comment)