If I'm building microservices using Node on Docker images - it's necessary to keep an idea of what version of Node I'm using.
The idea is - I'm going to be running Node locally in development - and then it still needs to work when running on a container.
If my Dockerfile looks like this:
FROM node:10.10-alpine
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 3001
CMD [ "npm", "start" ]
This is fine - except my local environment doesn't know which version of node I'm using.
Now I could just put 10.10
in my .nvmrc
file.
But then I have to remember to keep these in sync. Is there a better way to do it? Is there a node:alpine that respects .nvmrc?
nvm
stage to the build, but seems like a waste of time because it would add so much complexity. Maybe keeping the two versions in sync is best handled with a CI or Git hook.