1
\$\begingroup\$

I have a node project. My scripts section of package.json looks like this:

"scripts": {
 "postinstall": "gulp",
 "start": "node index.js",
 "test": "node ./node_modules/mocha/bin/mocha test"
},

My Dockerfile looks like this

FROM node:6.11-alpine
RUN mkdir -p /code
ADD . /code
WORKDIR /code
VOLUME /code
RUN npm install -g -s --no-progress yarn && \
 yarn && \
 yarn run test && \
 yarn cache clean

My docker-compose.yml looks like this:

version: "3"
services:
 web:
 build: .
 volumes:
 - .:/code
 command: "npm start"
 ports:
 - "8080:8080"
 networks:
 - internal
networks:
 internal:

This combination of ADD and VOLUME seems to give me what I need in terms of the javascript being there during the build stage and changes getting picked up in real time. However, I'm scared I'm doing something terribly wrong.

asked Sep 27, 2017 at 21:12
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

This Dockerfile should contain:

FROM node:6.11-alpine
COPY . /code
WORKDIR /code
RUN npm install -g -s --no-progress yarn && \
 yarn && \
 yarn run test && \
 yarn cache clean
EXPOSE 8080
CMD ["npm", "start"]

COPY copies your current directory to /code for building the final image (that holds compiled code normally).

In your docker-compose.yml, mounting a volume is used for your dev purposes, so that the files modified replace the ones on your image.

version: "3"
services:
 web:
 build: .
 volumes:
 - .:/code
 command: "npm run start:dev"
 ports:
 - "8080:8080"
 networks:
 - internal
networks:
 internal:
Sᴀᴍ Onᴇᴌᴀ
29.5k16 gold badges45 silver badges201 bronze badges
answered May 2, 2018 at 8:52
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.