R
Railway9mo ago
Liam

Install Newer Version of Node JS in Dockerfile

Howdy! I was wondering if anyone can help me modify this dockerfile to install a newer version of node. Thanks! Current Dockerfile
FROM alpine:3.14 AS build

WORKDIR /root

RUN apk add --update --no-cache nodejs npm

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

RUN npm install
RUN npm run build
RUN npm prune --production

FROM alpine:3.14

WORKDIR /root

COPY --from=build /root/node_modules ./node_modules
COPY --from=build /root/dist ./dist

RUN apk add --update --no-cache postgresql-client nodejs npm

ENTRYPOINT ["node", "dist/index.js"]
FROM alpine:3.14 AS build

WORKDIR /root

RUN apk add --update --no-cache nodejs npm

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

RUN npm install
RUN npm run build
RUN npm prune --production

FROM alpine:3.14

WORKDIR /root

COPY --from=build /root/node_modules ./node_modules
COPY --from=build /root/dist ./dist

RUN apk add --update --no-cache postgresql-client nodejs npm

ENTRYPOINT ["node", "dist/index.js"]
Solution:
```dockerfile FROM node:20.11.1-alpine AS build ENV NPM_CONFIG_UPDATE_NOTIFIER=false ENV NPM_CONFIG_FUND=false...
Jump to solution
8 Replies
Percy
Percy9mo ago
Project ID: N/A
Brody
Brody9mo ago
what version of node do you want?
Liam
Liam9mo ago
6cf9a94a-c057-4df7-8047-200d7bf6226b Oops sorry forgot the project ID, looking to install v20.11.1 (LTS)
Solution
Brody
Brody9mo ago
FROM node:20.11.1-alpine AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER=false
ENV NPM_CONFIG_FUND=false

WORKDIR /app

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

RUN npm ci
RUN npm run build
RUN npm prune --production

FROM node:20.11.1-alpine

WORKDIR /app

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

RUN apk add --update --no-cache postgresql16-client --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main

ENTRYPOINT ["node", "dist/index.js"]
FROM node:20.11.1-alpine AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER=false
ENV NPM_CONFIG_FUND=false

WORKDIR /app

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

RUN npm ci
RUN npm run build
RUN npm prune --production

FROM node:20.11.1-alpine

WORKDIR /app

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

RUN apk add --update --no-cache postgresql16-client --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main

ENTRYPOINT ["node", "dist/index.js"]
Liam
Liam9mo ago
That worked! I had to change npm ci to npm i but seems to be working now. Thanks!
Brody
Brody9mo ago
npm ci is preferred, what was the issue?
Liam
Liam9mo ago
My project exists in a mono repo and has no package-lock defined in the specific app. Going to fix this at some point since I fully understand its bad practice, but npm ci requires that the packge-lock exists. Just need to do some fiddeling with my monorepo to get it to work properly.
Brody
Brody9mo ago
gotcha
Want results from more Discord servers?
Add your server