I am trying to use Vagrant with docker provider on windows machine. I have Vagrantfile like this:
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "app" do |app|
app.vm.provider "docker" do |d|
d.name = "app"
d.build_dir = "."
d.vagrant_machine = "dockerhost"
d.vagrant_vagrantfile = "./DockerhostVagrantfile"
end
end
end
Docker host definition like this:
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", type: "smb"
config.vm.provision "docker"
config.vm.define "dockerhost"
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port",
guest: 8080, host: 8080
config.vm.provider :virtualbox do |vb|
vb.name = "dockerhost"
end
end
And Docker container like this:
FROM ubuntu:14.04
WORKDIR /vagrant/application
# .... install stuff
EXPOSE 8080
CMD ["/bin/bash"]
The problem is whenever I do vagrant docker-run app -- bash
and dockerimage has to be rebuild the process takes soo long.
// ....
app: Sending build context to Docker daemon 180.5 MB
app: Sending build context to Docker daemon 181 MB
app: Sending build context to Docker daemon 181.6 MB
// ....
I think this is because folder inside dockerhost
is mount with vboxfs
(which I found terribly slow).
Is there any way I can enforce Vagrant to use smb
?
Is problem with performance caused by anything else?
Finaly I found a solution how to use smb
instead of vboxfs
to mount docker build directory
.
As it states here https://github.com/mitchellh/vagrant/commit/745bdf676675e7b1f25fd7df5a4ed48b582b6dc7
It is possible to define host_vm_build_dir_options
property. So I modified my Vagrantfile
like this:
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "app" do |app|
app.vm.provider "docker" do |d|
d.name = "app"
d.build_dir = "."
d.vagrant_machine = "dockerhost"
d.vagrant_vagrantfile = "./DockerhostVagrantfile"
d.host_vm_build_dir_options = {
type: "smb"
}
end
end
end
Anyway the real problem with speed was caused by having Dockerfile
inside my root of project so all files were sent to the host. I solved that by moving it to Docker folder where is only the Dockerfile.