Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

best practices, build multi stage docker image securely

# --------------> The build image
FROM node:latest AS build
ARG NPM_TOKEN
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc && 
   npm ci --only=production && 
   rm -f .npmrc
 
# --------------> The production image
FROM node:lts-alpine@sha256:b2da3316acdc2bec442190a1fe10dc094e7ba4121d029cb32075ff59bb27390a
RUN apk add dumb-init
ENV NODE_ENV production
USER node
WORKDIR /usr/src/app
COPY --chown=node:node --from=build /usr/src/app/node_modules /usr/src/app/node_modules
COPY --chown=node:node . /usr/src/app
CMD ["dumb-init", "node", "server.js"]
Comment

best practices, build multi stage docker image securely

# --------------> The build image
FROM node:latest AS build
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN --mount=type=secret,mode=0644,id=npmrc,target=/usr/src/app/.npmrc npm ci --only=production
 
# --------------> The production image
FROM node:lts-alpine
RUN apk add dumb-init
ENV NODE_ENV production
USER node
WORKDIR /usr/src/app
COPY --chown=node:node --from=build /usr/src/app/node_modules /usr/src/app/node_modules
COPY --chown=node:node . /usr/src/app
CMD ["dumb-init", "node", "server.js"]


docker build . -t nodejs-tutorial --secret id=npmrc,src=.npmrc
DOCKER_BUILDKIT=1 docker build . -t nodejs-tutorial --build-arg NPM_TOKEN=1234 --secret id=npmrc,src=.npmrc
Comment

PREVIOUS NEXT
Code Example
Shell :: grep stack overflow 
Shell :: oracle cloud destination unrechable wireshark 
Shell :: combine two files as columns 
Shell :: nx test angular app 
Shell :: yaml file example ubuntu netplan error 
Shell :: scale variable with bc 
Shell :: how to change apache port in xampp 
Shell :: what is 127 of echo $? 
Shell :: bash execute last command by keyword 
Shell :: npm lavastore 
Shell :: run same command in different hosts 
Shell :: rsync only specific files but keep folders linux 
Shell :: nuget system.web.http.webhost 
Shell :: cookie clicker hack 
Shell :: imstall prettier 
Shell :: How to install ctlptl 
Shell :: arch linux deepin compositor 
Shell :: ubuntu cmd file last modified time 
Shell :: can i setup 2fa for my ubuntu ssh 
Shell :: how we can push code without pulling code on git branch 
Shell :: size of repository linux 
Shell :: bash script to replace hyphen with underscore 
Shell :: other-alternatives-of-column-command 
Shell :: install ChromeHeadless wsl 
Shell :: git view modified lines 
Shell :: scan full form nmap 
Shell :: ipmitool debug 
Shell :: hashcat-6.1.1.7z by kali linux 
Shell :: source script path 
Shell :: instal specific version software in archlinux 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =