3

Maybe I am overcomplicating this.

My goal is to create a Docker-based workflow on Windows for Node.js application development.

  1. In development time, I'd be able to run my app locally inside a container and still see the latest version without too much hassle (I don't want to rebuild the image everytime to see the latest).

  2. On the other hand, when I deploy to production, I want to have my source files "baked" into the container image with all the dependencies (npm install)

So I created two Vagrantfiles - one for the container and one for its host. Here's an extract of the latter:

Vagrant.configure(2) do |config|
  config.vm.provider "docker" do |docker|
    docker.vagrant_vagrantfile = "host/Vagrantfile"  # it references the host Vagrantfile
    docker.build_dir = "."  # we have a Dockerfile in the same dir
    docker.create_args = ['--volume="/usr/src/host:/usr/src/appcontainer:rw"']
  end
end

/usr/src/host is a directory which contains all of my source code (without node_modules). During the build of the Dockerfile, Docker copies the package.json to /usr/src/appcontainer and issues an npm install there which is fine for my second requirement (deploy to production)

But my first requirement was to change the source during development, so I mounted /usr/src/appcontainer as a volume pointing to the host directory /usr/src/host. However, this is not working, because /usr/src/host doesn't have a node_modules folder - this folder only exists in the container.

This whole problem seems to be easy - changing a file under Windows, see its changing both under the Linux host VM and in its container and vica versa... But I've got a bit stuck.

What is the best practice to achieve this syncing behaviour?

Zsolt
  • 3,203
  • 3
  • 28
  • 46

1 Answers1

1

However, this is not working, because /usr/src/host doesn't have a node_modules folder

You can use one of the approaches described in this question, for instance by using a data volume dedicated for node_modules.
Or mounting the host node_modules as a separate folder within the container.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283