Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

dockerfile

#### base ####
# cache our node version for installing later
FROM node:18.3.0-slim as node
FROM ubuntu:focal-20220531 as base
ENV NODE_ENV=production
# Avoid running nodejs process as PID 1 (use tini)
# You may also need development tools to build native npm addons:
# apt-get install gcc g++ make
RUN apt-get update 
    && apt-get -qq install -y --no-install-recommends 
    tini 
    && rm -rf /var/lib/apt/lists/*
EXPOSE 3000

# new way to get node, let's copy in the specific version we want from a docker image
# this avoids depdency package installs (python3) that the deb package requires
COPY --from=node /usr/local/include/ /usr/local/include/
COPY --from=node /usr/local/lib/ /usr/local/lib/
COPY --from=node /usr/local/bin/ /usr/local/bin/
# reset symlinks
RUN corepack disable && corepack enable

# create node user and group, then create app dir
RUN groupadd --gid 1000 node 
    && useradd --uid 1000 --gid node --shell /bin/bash --create-home node 
    && mkdir /app 
    && chown -R node:node /app

WORKDIR /app
USER node
COPY --chown=node:node package*.json yarn*.lock ./
RUN npm ci --only=production && npm cache clean --force

#### dev ####
# no source to be added, and assumes bind mount
FROM base as dev
ENV NODE_ENV=development
ENV PATH=/app/node_modules/.bin:$PATH
RUN npm install --only=development && npm cache clean --force
CMD ["nodemon", "index.js"]

#### source ####
FROM base as source
COPY --chown=node:node . .

#### test (as needed) ####
# FROM source as test
# ENV NODE_ENV=development
# ENV PATH=/app/node_modules/.bin:$PATH
# COPY --from=dev /app/node_modules /app/node_modules
# RUN npx eslint .
# RUN npm test
# CMD ["npm", "run", "test"]

#### prod ####
FROM source as prod
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["node", "index.js"]
Comment

PREVIOUS NEXT
Code Example
Javascript :: fetch js 
Javascript :: javascript array delete first element 
Javascript :: Select all elements with the same tag 
Javascript :: console shortcut chrome 
Javascript :: bin2hex in js 
Javascript :: adding background video angular 6 
Javascript :: js split string every n characters 
Javascript :: javascript select multiple values 
Javascript :: npm run start vs npm start 
Javascript :: what is vanilla javascript 
Javascript :: react native jest snapshot 
Javascript :: react native vector icons 
Javascript :: javascript websocket example code 
Javascript :: node get package.json version 
Javascript :: grepper extension firefox 
Javascript :: lodash remove multiple items from array 
Javascript :: how to remove an class in javascript 
Javascript :: moment get timestamp 
Javascript :: merge-sort js 
Javascript :: js get all dublicates indexes in array 
Javascript :: javascript Compare two arrays regardless of order 
Javascript :: javascript check if property exists in object 
Javascript :: js retour à la ligne 
Javascript :: javascript reload page without refresh 
Javascript :: how to remove particular value in dictionary in nodehs 
Javascript :: javascript current target 
Javascript :: input two decimal places javascript 
Javascript :: get element by id inside first element by class in JavaScript 
Javascript :: npm font awesome 5 angular 7 
Javascript :: Extract the domain name from a URL 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =