Install docker in vagrant

2019-05-10 06:26发布

问题:

I am trying to install docker in a vagrant box, I followed the steps on the docker website

But when I run vagrant up in the docker/ directory that is downloaded through git I get this error message.

"There is a syntax error in the following Vagrantfile. The syntax error message is reproduced below for convenience:

/docker/Vagrantfile:146: syntax error, unexpected ':', expecting kEND
    override.vm.synced_folder ".", "/vagrant", disabled: true"

How do I resolve this so that I can connect into the vagrant box, I get the same message is I run the command "vagrant ssh"

回答1:

In the last version of vagrant ,the docker provisioner can support docker now. Try it: http://docs.vagrantup.com/v2/provisioning/docker.html



回答2:

Looks like you use an old version of Vagrant. Try to upgrade. This can help.



回答3:

This example vagrant file will install Docker version 1.3.2 for you. You can leave d.version out if you don't care what version of Docker gets downloaded.

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "hashicorp/precise64"

  config.vm.provision "docker" do |d|
      d.version = "1.3.2"
  end 
end


回答4:

I built a very basic vagrantfile that sets up ubuntu with docker installed.

I use it occasionally for testing docker

https://github.com/thestonefox/vagrant-docker



回答5:

My experience:

I was behind a proxy so I had to configure it in vagrant. First I install the plugin to set the proxy:

vagrant plugin install vagrant-proxyconf

Then I completed the example above:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "hashicorp/precise64"
  config.yum_proxy.http = "http://proxy.internal.lcl:8080/"
  config.proxy.http     = "http://proxy.internal.lcl:8080/"
  config.proxy.https    = "http://proxy.internal.lcl:8080/"
  config.proxy.no_proxy = "localhost,127.0.0.1"  
  config.vm.provision "docker" do |d|
      d.version = "latest"
  end 
end

Finally I had to bypass the proxy somehow for docker with this shell command:

export NO_PROXY="/var/run/docker.sock"

Result:

root@precise64:~# docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef

Hope it helps.