Skip to content
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

Vagrant executing docker commands fails #12

Open
thasmo opened this issue Jun 1, 2014 · 9 comments
Open

Vagrant executing docker commands fails #12

thasmo opened this issue Jun 1, 2014 · 9 comments

Comments

@thasmo
Copy link

thasmo commented Jun 1, 2014

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
Copy link
Author

thasmo commented Jun 1, 2014

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

@stigkj
Copy link

stigkj commented Jun 1, 2014

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

@thasmo
Copy link
Author

thasmo commented Jun 1, 2014

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.

@adambiggs
Copy link

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?

@fracz
Copy link

fracz commented Jun 27, 2014

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.

@dklotz
Copy link

dklotz commented Aug 10, 2014

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

@fracz
Copy link

fracz commented Aug 24, 2014

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

@ddmrs
Copy link

ddmrs commented Jul 31, 2015

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.

@dklotz
Copy link

dklotz commented Aug 4, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants