Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

lxc

nfs

I am working on a website powered by Node. So I have made a simple Dockerfile that adds my site's files to the container's FS, installs Node and runs the app when I run the container, exposing the private port 80.

But if I want to change a file for that app, I have rebuild the container image and re-run it. That takes some seconds.

Is there an easy way to have some sort of "live sync", NFS like, to have my host system's app files be in sync with the ones from the running container?

This way I only have to relaunch it to have changes apply, or even better, if I use something like supervisor, it will be done automatically.

like image 347
conradkleinespel Avatar asked Sep 18 '13 17:09

conradkleinespel


People also ask

Can a docker container access host files?

Namespaces and Docker Docker volumes are convenient for sharing files from the host and keeping larger files out of image layers. They can also be significantly faster for filesystem access than the container filesystem, as some storage backends impose significant overheads for certain workloads.


Video Answer


1 Answers

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.

like image 168
creack Avatar answered Sep 22 '22 09:09

creack