Docker: How to live sync host folder with container folder?

If you are under OSX, those kind of volume shares can become very slow, especially with node-based apps ( a lot of files ). For this issue, http://docker-sync.io can help, by providing a volume-share like synchronisation, without using volume shares, this usually speeds up your container read/write speed of the code-directory from 50-80 times, depending on what docker-machine you use.

For performance see https://github.com/EugenMayer/docker-sync/wiki/4.-Performance and for easy examples how to use it, see the boilerplates https://github.com/EugenMayer/docker-sync-boilerplate for your case the unison example https://github.com/EugenMayer/docker-sync-boilerplate/tree/master/unison is the one you would need for NFS like sync


docker run -dit -v ~/my/local/path:/container/path/ myimageId

For /container/path/ you could use for instance /usr/src/app. The flags:

-d = detached mode,

-it = interactive,

-v + paths = specifies the volume.

(If you just care about the volume, you can drop the -dit flag.)

Docker run reference


You can use volumes in order to do this. You have two options:

  1. Docker managed volumes:

    docker run -v /src/path nodejsapp
    docker run -i -t -volumes-from <container id> bash
    

The file you edit in the second container will update the first one.

  1. Host directory volume:

    docker run -v `pwd`/host/src/path:/container/src/path nodejsapp
    

The changes you make on the host will update the container.

Tags:

Docker

Nfs

Lxc