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 :: javascript calculate days between dates 
Javascript :: javascript set date to timezone 
Javascript :: chrome-doesnt-scale-below-x-500px 
Javascript :: get the first word from a string jquery 
Javascript :: json opposite of stringify 
Javascript :: set default terminal vscode windows 
Javascript :: how to get current year in javascript 
Javascript :: javascript clone array without reference 
Javascript :: delete node modules from multiple projects 
Javascript :: js does forEach respect order 
Javascript :: launch.json for debug vuejs in vcsode 
Javascript :: how to convert char to number in js 
Javascript :: how to serve build react 
Javascript :: jquery google cdn 
Javascript :: check truthy or falsy javascript 
Javascript :: onclick change text color javascript 
Javascript :: vscode ejs formatter 
Javascript :: javascript generate unique id 
Javascript :: Não é possível chamar Veiculo.create(). O método create não foi configurado. O PersistedModel não foi conectado corretamente a uma DataSource! 
Javascript :: node mailer office 365 
Javascript :: javascript split array into chuncks of 
Javascript :: how to check if a folder exists in node js 
Javascript :: create link and click javascript 
Javascript :: higher order functions event 
Javascript :: rafraichir page javascript 
Javascript :: nodejs tcp client 
Javascript :: js compare lists 
Javascript :: input text react 
Javascript :: how to connect mongoose database with nodejs 
Javascript :: node express js set server timeout 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =