Reputation: 323
When running "docker-compose up", I get the following error:
npm info lifecycle [email protected]~dev: [email protected]
> [email protected] dev /code/app
> nodemon -L ./bin/www --exec babel-node
sh: 0: getcwd() failed: No such file or directory
path.js:1144
cwd = process.cwd();
^
Error: ENOENT: no such file or directory, uv_cwd at Error (native)
at Object.resolve (path.js:1144:25)
at Function.Module._resolveLookupPaths (module.js:361:17)
at Function.Module._resolveFilename (module.js:431:31)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous>
(/usr/local/lib/node_modules/nodemon/bin/nodemon.js:3:11)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
npm info lifecycle [email protected]~dev: Failed to exec dev script
npm ERR! Linux 4.9.36-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v6.3.1
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: `nodemon -L ./bin/www --exec babel-node`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'nodemon -L ./bin/www --
exec babel-node'.
My dockerfile looks like this:
FROM joakimbeng/node-zeromq
RUN mkdir /code/
RUN mkdir /code/app/
COPY package.json /code/
WORKDIR /code
RUN npm install -g nodemon babel-cli
RUN npm install
WORKDIR /code/app
CMD ["npm", "run", "dev"]
And my service like this:
node:
build: ./node/
ports:
- "3000:3000"
volumes:
- ../code:/code/app
links:
- mongodb
- python
environment:
- NODE_ENV=dev
- NODE_PATH=/code/node_modules
- MONGODB_ADDRESS=mongodb
- PYTHON_ADDRESS=python
I've tried to delete all containers and images and run the whole thing again, but the same error appears. It seems to build fine when running "docker-compose build".
What I'm trying to accomplish here is: 1. Let the container handle all the dependencies (node modules) 2. Mount my code base to the container 3. Use nodemon for hot reload
Upvotes: 0
Views: 8745
Reputation: 146520
Your issue is the volume sharing. When you share a volume from host to the container. If the folder already exists in the container then the host container will shadow the container folder.
If you have 10 files inside container and 0 files on your host, then after volume mapping your container will see 0 files. Because the the host folder is mounted and it has nothing. So you Dockerfile
statement
RUN npm install
Is effectively gone, if the host volume doesn't have the npm install done. Luckily the solution is simple. You can change your CMD
to below
CMD bash -c "npm install && npm run dev"
In case you don't want to change the Dockerfile
you can add the below in your docker-compose.yml
file for the node
service
command: bash -c "npm install && npm run dev"
Edit (14-Aug):
If you want your dependencies to be in image then you need to make few changes in your docker-compose.yml
, what you need is the internal code to be left alone and just linking the node_modules
from that directory to a you app directory
node:
build: ./node/
ports:
- "3000:3000"
volumes:
- ../code:/code/app
command: bash -c "ln -fs /code/node_modules /code/app/node_modules && exec npm run dev"
links:
- mongodb
- python
environment:
- NODE_ENV=dev
- NODE_PATH=/code/node_modules
- MONGODB_ADDRESS=mongodb
- PYTHON_ADDRESS=python
Another point i notice is that your running package.json
install in /code
and putting your code /code/app
which is probably wrong when you run the image. But with the new edit I have suggested above, this should work
Upvotes: 0
Reputation: 323
I ended up with something similar to what I did initially. Not sure what caused the error in my OP, but the difference seems to be that I mount my dependencies in a different directory.
Dockerfile:
FROM joakimbeng/node-zeromq
RUN mkdir /code/
RUN mkdir /dependencies/
COPY package.json /dependencies/
WORKDIR /dependencies/
RUN npm install -g nodemon babel-cli
npm install
WORKDIR /code/
CMD bash -c "npm run dev"
Service in docker-compose:
node:
build: ./node/
ports:
- "3000:3000"
volumes:
- ../code/:/code
links:
- mongodb
- python
environment:
- NODE_ENV=dev
- NODE_PATH=/dependencies/node_modules
- MONGODB_ADDRESS=mongodb
- PYTHON_ADDRESS=python
This way my dependencies are only installed on build.
Upvotes: 2