Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker and file sharing on OS X

Ok. I am playing around with different tools to prepare dev environment. Docker is nice option. I created the whole dev environment in docker and can build a project in it.

The source code for this project lives outside of docker container (on the host). This way you can use your IDE to edit it and use docker just to build it.

However, there is one problem

a) Docker on OS X uses VM (VirtualBox VM)

b) File sharing is reasonably slow (way slower than file IO on host)

c) The project has something like a gazzilion files (which exaggerate problems #a an #b).

If I move source code in the docker, I will have the same problem in IDE (it will have to access shared files and it will be slow).

I heard about some workaround to make it fast. However, I can't seem to find any information on this subject.

Update 1

I used Docker file sharing feature (meaning I run)

docker run -P -i  -v <VMDIR>:<DOCKERDIR> -t <imageName> /bin/bash

However, sharing between VM and Docker isn't a problem. It's fast.

The bottle neck is sharing between host and VM.

like image 399
Victor Ronin Avatar asked Jan 16 '15 18:01

Victor Ronin


1 Answers

The workaround I use is not to use boot2docker but instead have a vagrant VM provisioned with docker. No such big penalty for mounting folders host->vagrant->docker.

On the downside, I have to pre-map folders to vagrant (basically my whole work directory) and pre-expose a range of ports from the vagrant box to the host to have access to the docker services directly from there.

On the plus side, when I want to clean unused docker garbage (images, volumes, etc.) I simply destroy the vagrant vm and re-create it again :)

Elaboration

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "trusty-docker"
  config.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box"
  config.vm.provision "docker"

  #by default we'll claim ports 9080-9090 on the host system
  for i in 9080..9090
    config.vm.network :forwarded_port, guest: i, host: i
  end

  #NB: this folder mapping will not have the boot2docker issue of slow sync
  config.vm.synced_folder "~/work", "/home/vagrant/work"
end

Having that:

host$ vagrant up && vagrant ssh
vagrant$ docker run -it --rm -v $(pwd)/work:/work ubuntu:12.04 find /work
like image 138
Mykola Gurov Avatar answered Sep 21 '22 13:09

Mykola Gurov