2

I am using docker-sync to speed up the dev environment file updates on my node.js application.

Right now I am trying to cache npm install command by moving package.json to the image and running npm install when the image is created.

Dockerfile:

ADD ./package.json /app/user/
RUN npm install

Then I use the following configuration for docker-sync:

docker-sync.yml

version: "2"
options:
  verbose: true
syncs:
  appcode-rsync-sync:
    src: './'
    sync_host_ip: 'auto'
    sync_host_port: 10872
    sync_strategy: 'rsync'
    sync_excludes: [ 'public/lib/', 'public/dist/', 'node_modules/']

And here is the docker-compose.yml:

services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - appcode-rsync-sync:/app/user:nocopy
    command: grunt

volumes:
  appcode-rsync-sync:
    external: true

The problem is that npm install installs all the required packages in node_modules, public_lib, public_dist directories, but after mounting the docker-sync volume it will remove all those directories from the container (even though they are in the sync_excludes.)

I there any option or work around to prevent docker-sync to remove the files which are on the container?

-I already tried removing nocopy but it did not help

Sina Masnadi
  • 1,516
  • 17
  • 28

1 Answers1

2

Using this answer I modified docker-compose.yml to address the problem.

docker-compose.yml:

services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - /app/user/public/lib/
      - /app/user/public/dist/
      - /app/user/node_modules/
      - appcode-rsync-sync:/app/user:nocopy
    command: grunt

volumes:
  appcode-rsync-sync:
    external: true

As you can see I added the following volumes:

- /app/user/public/lib/
- /app/user/public/dist/
- /app/user/node_modules/
Sina Masnadi
  • 1,516
  • 17
  • 28