Vagrant: Error on installing Docker using the Docker provisioner

Created on 8 Jun 2014  路  13Comments  路  Source: hashicorp/vagrant

The following happens when Vagrant creates the Docker host on Windows:

Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
    default: Vagrant will now create or start a local VM to act as the Docker
    default: host. You'll see the output of the `vagrant up` for this VM below.
    default:
    default: Importing base box 'phusion/ubuntu-14.04-amd64'...
    default: Matching MAC address for NAT networking...
    default: Checking if box 'phusion/ubuntu-14.04-amd64' is up to date...
    default: Setting the name of the VM: Docker
    default: Clearing any previously set forwarded ports...
    default: Clearing any previously set network interfaces...
    default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
    default: Running 'pre-boot' VM customizations...
    default: Booting VM...
    default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Machine booted and ready!
    default: Checking for guest additions in VM...
    default: Mounting shared folders...
    default: /vagrant => S:/Project/vagrant.docker-host
    default: Running provisioner: docker...
    default: Installing Docker (latest) onto machine...
    default: Configuring Docker to autostart containers...
==> default: Syncing folders to the host VM...
    default: Mounting shared folders...
    default: /var/lib/docker/docker_1402252891_7417 => S:/Project/docker.test
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/08 18:41:49 Get http:///var/run/docker.sock/v1.12/containers/json?all=1: dial unix /var/run/docker.sock: permission denied

Stdout:

This is the Vagrantfile for the Docker host:

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

  config.vm.provider 'virtualbox' do |provider|
    provider.gui = false
    provider.name = 'Docker'
    provider.customize ['modifyvm', :id, '--cpus', 2]
    provider.customize ['modifyvm', :id, '--acpi', 'on']
    provider.customize ['modifyvm', :id, '--memory', 2048]
    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.gui = false
      provider.vmx['displayName'] = 'Docker'
      provider.vmx['numvcpus'] = 2
      provider.vmx['memsize'] = 2048
    end
  end

  config.ssh.forward_agent = true
end

Nevertheless the Docker host seems to be running afterwards. Haven't tested further yet.

documentation enhancement providedocker

Most helpful comment

Isn't this the solution that works? Put it right after config.vm.provision 'docker' line

  # The following line terminates all ssh connections. Therefore
  # Vagrant will be forced to reconnect.
  # That's a workaround to have the docker command in the PATH
  config.vm.provision "shell", inline:
     "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"

All 13 comments

The vagrant user seems to be member of the docker group, so this shouldn't be the problem. Weird.

Ah, the issue is that you need to log out and log back in. The Docker provisioner i nstaller doesn't do this because all the solutions are pretty hacky. But google how to do that in a shell and it'll work.

The root cause: group membership changes only take effect on log out and log in.

We might be able to automate this in the future in some hacky way, actually. Let me reopen and tag as enhancement.

I'm using a custom VM referenced with vagrant_vagrantfile in my docker-based project, that proxy vm installs docker (and adds the vagrant user to the group docker) with a normal shell provisioning script defined in its Vagrantfile. Yet when I 'vagrant up' my real (i.e. not the proxy-vm) docker-vagrant-project for the first time, the proxy vm is started yet creating the docker container fails with the following:

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/08/08 16:46:19 Get http:///var/run/docker.sock/v1.13/containers/json?all=1: dial unix /var/run/docker.sock: permission denied

The proxy VM keeps running after that and when I try to start the docker-based VM again, it works fine. Where should I add the "logging in / out" workaround mentioned in the comments here? As a provisioning script in the Vagrantfile of my proxy-base-docker-VM? Or somehow in the Vagrantfile of the "real" dockerized project?

@mitchellh could you maybe document the workaround for the time being somewhere? I know how to login/logout/newgrp in a script, I just haven't been able to figure out where to put this in the vagrant/docker context. (also: didn't you want to reopen this issue?)

@mitchellh this issue is still existent and makes using vagrant with a custom docker host VM really annoying. Could you at least document the login/logout workaround thats supposed to work somewhere? I haven't been able to configure vagrant with a custom base VM that doesn't error out on the first try with this error. Trying again helps, but having to tell all our developers "just execute the command a second time" isn't really a good workaround...

@dklotz I think we can probably do better and detect these errors and maybe show a human-friendly error. Tagged as docs and reopening.

Isn't this the solution that works? Put it right after config.vm.provision 'docker' line

  # The following line terminates all ssh connections. Therefore
  # Vagrant will be forced to reconnect.
  # That's a workaround to have the docker command in the PATH
  config.vm.provision "shell", inline:
     "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"

@kmmbvnr thanks, yes, that seems to help! although I'm unable to really verify it thanks to another docker-related issue (#4723)

I can say that the fix provided by @kmmbvnr solved this issue for me :)

My Vagrant VM is in a similar state:

No matter what command I run: vagrant status, vagrant destroy, vagrant ssh, etc, I always get the "A Docker command executed by Vagrant didn't complete successfully!" message. Is there any way to get this "unstuck" without completely wiping the .vagrant directory and starting over?

Hey everyone,

The next version of Vagrant will allow you to use your own custom Docker host. As Mitchell said, we could build a really hacky solution to somehow force a user-login-logout, but none of the solutions are very good or cross-compatible. The solution @kmmbvnr posted above is a really great option. Thanks! 馃槃

Was this page helpful?
0 / 5 - 0 ratings