Answer a question

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.

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.

Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐