TL;DR Working example, clone and try: https://github.com/xbx/base-server
You need a node_modules in your computer (outside image) for debugging purposes first (before run the container).
If you want debug only node_modules:
volumes:
- /path/to/node_modules:/usr/src/app/node_modules
If you want debug both your code and the node_modules:
volumes:
- .:/usr/src/app/
Remember that you will need run npm install
at least one time outside the container (or copy the node_modules directory that the docker build
generates). Let me now if you need more details.
Edit. So, without the need of npm in OSX, you can:
docker build
and then docker cp <container-id>:/path/to/node-modules ./local-node-modules/
. Then in your docker-compose.yml mount those files and troubleshot whatever you want.
- Or,
docker build
and there (Dockerfile) do the npm install
in another directory. Then in your command (CMD or docker-compose command) do the copy (cp
) to the right directory, but this directory is mounted empty from your computer (a volume in the docker-compose.yml) and then troubleshot whatever you want.
Edit 2. (Option 2) Working example, clone and try: https://github.com/xbx/base-server
I did it all automatically in this repo forked from the yours.
Dockerfile
FROM node:6.3
# Install app dependencies
RUN mkdir /build-dir
WORKDIR /build-dir
COPY package.json /build-dir
RUN npm install -g babel babel-runtime babel-register mocha nodemon
RUN npm install
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN ln -s /build-dir/node_modules node_modules
# Bundle app source
COPY . /usr/src/app
EXPOSE 1234
CMD [ "npm", "start" ]
docker-compose.yml
web:
build: .
ports:
- "1234:1234"
links:
- db # liaison avec la DB
environment:
PORT: 1234
command: /command.sh
volumes:
- ./src/:/usr/src/app/src/
- ./node_modules:/usr/src/app/node_modules
- ./command.sh:/command.sh
db:
image: mongo:3.3
ports:
- "27017:27017"
command: "--smallfiles --logpath=/dev/null"
command.sh
#!/bin/bash
cp -r /build-dir/node_modules/ /usr/src/app/
exec npm start
Please, clone my repo and do docker-compose up
. It does what you want.
PS: It can be improved to do the same in a better way (ie best practices, etc)
I'm in OSX and it works for me.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…