Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

dockerfile nodejs

FROM node:10-alpine

RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

WORKDIR /home/node/app

COPY package*.json ./

USER node

RUN npm install

COPY --chown=node:node . .

EXPOSE 8080

CMD [ "node", "index.js" ]
Comment

simple nodejs dockerfile

FROM node:12-alpine
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production
COPY . .
CMD ["node", "/app/src/index.js"]
Comment

sample docker for node js

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
Comment

docker nodejs

# getting a copy of ubuntu for docker
pull ubuntu

# run ubuntu image in interactive mode 
docker run -it ubuntu  

# run ubuntu image in interactive mode while mounting the terminal
# current working directory to ubuntu home folder
docker run -v ${PWD}:/home -it ubuntu

# run ubuntu image in interactive mode while mounting the terminal
# mounting an absolute path on my computer directory to ubuntu home folder
docker run -v /Users/codecaine/Desktop:/home -it ubuntu

# run ubuntu image in interactive mode while mounting the terminal
# mounting an absolute path on my computer directory to ubuntu home/data
# directory
docker run -v /Users/codecaine/Desktop:/home/data -it ubuntu

# run these two commands to be able to install packages with apt-get
apt-get -y update
apt-get -y curl

# installing python and nodejs with apt-get
apt-get -y python3.10 
apt-get -y install nodejs
Comment

docker nodejs

############### RECOMMENDED DOCKER IMAGE VERSION ###############
# <node version>-buster (debian 10) -> latest version
# <node version>-stretch (debian 9) -> stable version
# <node version>-alpine3.15 (alpine) -> small size version
################################################################
 
######################
# START STAGE 1
######################
FROM node:14.19.1-buster as start # change node version with same your app use
USER ${USER}
ENV NODE_OPTIONS=--max_old_space_size=32768
ADD ./package.*json ./
ADD . ./
 
#######################
# UPGRADE STAGE 2
#######################
FROM start as upgrade
COPY --from=start . ./
RUN apt-get autoremove  # this command only for debian image version, change command if you use alpine linux image version
  && apt-get autoclean 
  && apt-get update 
  && apt-get upgrade -y 
  && apt-get install build-essential -y
 
#######################
# FINAL STAGE 3
#######################
FROM upgrade as final
COPY --from=upgrade . ./
RUN rm -rf node_modules 
  && npm cache clean -f 
  && npm config delete proxy 
  delete https-proxy 
  -g delete proxy 
  -g delete https-proxy 
  set strict-ssl false 
  set registry "http://registry.npmjs.org" 
  set fetch-retries 10 
  set fetch-retry-factor 20 
  set fetch-retry-mintimeout 6000000 
  set fetch-retry-maxtimeout 12000000 
  set audit false 
  set cache-min 3600 
  set unsafe-perm true 
  && npm i -g --unsafe-perm 
  node-gyp -g 
  @xpack-dev-tools/windows-build-tools@latest -g 
  pm2 -g  # remove this if you not run your app with pm2
  && npm i --verbose --no-audit 
  && npm rebuild bcrypt --build-from-source  # remove this if you no need
  && npm run build  # change with your command app
  && npm config ls -l
EXPOSE 3000 # change with your port app
CMD npm run prod # change with your command app
Comment

PREVIOUS NEXT
Code Example
Javascript :: js fetch api 
Javascript :: downgrade node version 
Javascript :: node app listen change ip 
Javascript :: add eslint dependencies for cypress 
Javascript :: parse string to int nodejs 
Javascript :: angular material remove outline 
Javascript :: react native filter list 
Javascript :: javascript get nested element 
Javascript :: BREAK A LINE on JS 
Javascript :: clear the command prompt node 
Javascript :: mongoose findone exclude perticular field 
Javascript :: lpad javascript 
Javascript :: how to make a popup in javascript -html 
Javascript :: sum values in array javascript 
Javascript :: mongoBD $inc operator 
Javascript :: remove object in array javascript 
Javascript :: substr() javascript 
Javascript :: milliseconds to date javascript 
Javascript :: merge sort javascript 
Javascript :: how to install jsonwebtoken in next js 
Javascript :: mapdispatchtoprops 
Javascript :: photo in React native 
Javascript :: vue mounted refresh page once 
Javascript :: javascript insert html before element 
Javascript :: python parse single quote json 
Javascript :: remove empty option from bootstrap select javascript 
Javascript :: two decimal places javascript 
Javascript :: javascript get element by id and class 
Javascript :: jquery validation focus field on error 
Javascript :: angular get device information 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =