Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

multi stage node js dockerfile

#
# ---- Base Node ----
FROM alpine:3.5 AS base
# install node
RUN apk add --no-cache nodejs-current tini
# set working directory
WORKDIR /root/chat
# Set tini as entrypoint
ENTRYPOINT ["/sbin/tini", "--"]
# copy project file
COPY package.json .

#
# ---- Dependencies ----
FROM base AS dependencies
# install node packages
RUN npm set progress=false && npm config set depth 0
RUN npm install --only=production 
# copy production node_modules aside
RUN cp -R node_modules prod_node_modules
# install ALL node_modules, including 'devDependencies'
RUN npm install

#
# ---- Test ----
# run linters, setup and tests
FROM dependencies AS test
COPY . .
RUN  npm run lint && npm run setup && npm run test

#
# ---- Release ----
FROM base AS release
# copy production node_modules
COPY --from=dependencies /root/chat/prod_node_modules ./node_modules
# copy app sources
COPY . .
# expose port and define CMD
EXPOSE 5000
CMD npm run start
Comment

A multi-stage Dockerfile for building nodejs

# 
# Build stage 1.
# This state builds our TypeScript and produces an intermediate Docker image containing the compiled JavaScript code.
#
FROM node:10.15.2

WORKDIR /usr/src/app
COPY package*.json ./
COPY tsconfig.json ./
RUN npm install
COPY ./src ./src
RUN npm run build

#
# Build stage 2.
# This stage pulls the compiled JavaScript code from the stage 1 intermediate image.
# This stage builds the final Docker image that we'll use in production.
#
FROM node:10.15.2

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY --from=0 /usr/src/app/build ./build
EXPOSE 80
CMD npm start
Comment

multi stage node js dockerfile

FROM node as builder
LABEL org.opencontainers.image.vendor=demo-frontend
LABEL works.buddy.intermediate=true
WORKDIR /root/
COPY ["package.json", "package-lock.json", "./"]
RUN ["npm", "install"]
COPY ["webpack.config.js", "./"]
COPY ["src/", "./src/"]
RUN ["npm", "run", "build"]
RUN ["/bin/bash", "-c", "find . ! -name dist ! -name node_modules -maxdepth 1 -mindepth 1 -exec rm -rf {} ;"]

FROM node:alpine
LABEL org.opencontainers.image.vendor=demo-frontend
LABEL org.opencontainers.image.title="Buddy Team"
WORKDIR /root/
COPY --from=builder /root/ ./
ENTRYPOINT ["node", "/root/node_modules/.bin/http-server" , "./dist/"]
EXPOSE 8080
Comment

multi stage node js dockerfile

# Build Stage 1
# This build created a staging docker image
#
FROM node:10.15.2-alpine AS appbuild
WORKDIR /usr/src/app
COPY package.json ./
COPY .babelrc ./
RUN npm install
COPY ./src ./src
RUN npm run build

# Build Stage 2
# This build takes the production build from staging build
#
FROM node:10.15.2-alpine
WORKDIR /usr/src/app
COPY package.json ./
COPY .babelrc ./
RUN npm install
COPY --from=appbuild /usr/src/app/dist ./dist
EXPOSE 4002
CMD npm start
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery if input has empty white space 
Javascript :: remove the last element of an array javascript 
Javascript :: yarn react-bootstrap 
Javascript :: how to format numbers as currency string js 
Javascript :: float js precision 
Javascript :: chart.js change font color 
Javascript :: how to calculate average of array in javascript 
Javascript :: move an element into another jquery 
Javascript :: get how much i scroll in js 
Javascript :: 16/27.5 
Javascript :: run a nodejs file infinite loop 
Javascript :: invoke lambda nodejs 
Javascript :: js remove quotes from string 
Javascript :: jquery ajax google api 
Javascript :: truthy or falsy value javascript 
Javascript :: add readonly attribute jquery 
Javascript :: Invariant Violation: requireNativeComponent: "RNSScreen" was not found in the UIManager 
Javascript :: javascript size of variable in kb 
Javascript :: if button is keeping pressed execute increment javascript 
Javascript :: javascript get diagonals of array 
Javascript :: javascript split array into chunks of 
Javascript :: nodejs fs directory exists 
Javascript :: simulate a user click 
Javascript :: $.dialog after create focus 
Javascript :: js random number 
Javascript :: js nearest 100 
Javascript :: Remove all child nodes of a list: 
Javascript :: remove extra spaces javascript 
Javascript :: angular generate component without spec 
Javascript :: next.js how to add google fonts 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =