open-vagrant-boxes icon indicating copy to clipboard operation
open-vagrant-boxes copied to clipboard

Vagrant executing docker commands fails

Open thasmo opened this issue 11 years ago • 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!

thasmo avatar Jun 01 '14 18:06 thasmo

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! :)

thasmo avatar Jun 01 '14 18:06 thasmo

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

stigkj avatar Jun 01 '14 18:06 stigkj

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.

thasmo avatar Jun 01 '14 18:06 thasmo

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?

adambiggs avatar Jun 18 '14 21:06 adambiggs

See this answer: https://github.com/mitchellh/vagrant/issues/3998#issuecomment-45506726 The logout / login indeed solves the problem for me. Also ensure that the user that is running docker belongs to docker group.

fracz avatar Jun 27 '14 14:06 fracz

@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...

dklotz avatar Aug 10 '14 15:08 dklotz

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

fracz avatar Aug 24 '14 15:08 fracz

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 avatar Jul 31 '15 14:07 ddmrs

@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): https://github.com/mitchellh/vagrant/issues/3998#issuecomment-60359659

dklotz avatar Aug 04 '15 14:08 dklotz