node.js - Docker compose volume mapping with NodeJS app -


i trying achieve incredibly basic, have been going @ couple of evenings , still haven't found solid (or any) solution. have found similar topics on , followed on there no avail, have created github repo specific case.

what i'm trying do:

  • be able provision nodejs app using docker-compose -d (i plan add further containers in future, omitted example)
  • ensure code mapped via volumes don't have re-build every time make change code locally.

my guess issue i'm encountering mapping of volumes causing files lost/overwritten within container, instance in of variations i've tried folders being mapped individual files not.

i've created simple repo illustrate issue, checkout , run docker-compose -d see issue, container dies due to:

error: cannot find module '/src/app/app.js'

the link repo here: https://github.com/josephmcdermott/nodejs-docker-issue, pr's welcome , if can solve me i'd eternally grateful.

update: please see solution code below, kind ldg

dockerfile

from node:4.4.7  run mkdir -p /src copy . /src workdir /src run npm install  expose 3000  cmd ["node", "/src/app.js"] 

docker-compose.yml

app:   build: .   volumes:     - ./app:/src/app 

folder structure:

- app - - * (files want sync , regularly update) - app.js (initial script call files within app/) - dockerfile - docker-compose.yml - package.json 

in compose file, last line - /src/app/node_modules mapping on previous volume. if mount /scr/app node_modules created in linked volume. this:

app:   build: .   volumes:     - ./app:/src/app 

if want keep entire /app directory linked volume, you'll need either npm install when starting container (which insure picks updates) or don't link volume , update dockerfile copy entire /app directory. nice because gives self-contained image. dockerize node.js apps way. can run npm test appropriate verify image.

if need create linked volume script file want able edit (or if app generates side-effects), can link directory or file via docker volumes.

btw, if want make sure don't copy contents of directory in future, add .dockerignore (as .gitignore).


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -