patternjavascriptdockerMinor
Preinstall packages for a nodejs Docker Image according to package.json
Viewed 0 times
imagepackagedockerpreinstallnodejsforjsonpackagesaccording
Problem
I would like to prepare a Docker image for a nodejs project. The developers use package.json to list their node module dependencies. I would like to prepare the Docker image (as base on the Dockerfile), with most of the node_modules already installed "globally" on the image.
Is there a best practice to prepare nodejs images?
Is there a best practice to prepare nodejs images?
Solution
Depend of life cycle of you app, because Node libraries and dependences change or end life to obsolet, so if you app constant change version to deploy, you can use docker tag for describe version or time when it build image, is a good practice, so Dockerfile shall copy package.json, and too look when you need change image source OS, by example change ubuntu linux to alpine , many dependences or how to install "npm" and dependences for node, a example:
well , hope it help you
FROM alpine:3.8
# Update
RUN apk add --update nodejs nodejs-npm
# Install app dependencies
COPY package.json /src/package.json
RUN cd /src; npm install
# Bundle app source
COPY . /src
EXPOSE 5000
CMD ["node","src/index.js"]well , hope it help you
Code Snippets
FROM alpine:3.8
# Update
RUN apk add --update nodejs nodejs-npm
# Install app dependencies
COPY package.json /src/package.json
RUN cd /src; npm install
# Bundle app source
COPY . /src
EXPOSE 5000
CMD ["node","src/index.js"]Context
StackExchange DevOps Q#4941, answer score: 1
Revisions (0)
No revisions yet.