'Macbook m1 node js docker image build failed
What's wrong? I should wait for the production docker?
This is docker config:
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
Solution 1:[1]
You need to install python as part of your build process. For more details how to install python check here
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ .
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
Solution 2:[2]
You need python with make
and g++
to build your dependencies.
FROM node:14-alpine as frontbuild
#RUN apk add --no-cache python2 make g++ WORKDIR /tmp
COPY ./front/package.json .
RUN apk add --update --no-cache python2 make gcc libsass g++
RUN npm install --no-optional --only-production
COPY front /tmp
ARG VUE_APP_BASE_URL ENV VUE_APP_BASE_URL $VUE_APP_BASE_URL ENV NODE_ENV production
RUN npm run build
Solution 3:[3]
Try running it with linux/amd64.
In your docker config change:
FROM node:lts-alpine as build-stage
to
FROM --platform=linux/amd64 node:lts-alpine as build-stage
Solution 4:[4]
Well, you need python. And the already provided answers here will provide you with that and the minimalist might be looking for something like that.
Another option would be not to use the alpine version of node (which comes for good reasons with a minimized footprint). I've personally accepted the overhead of a bigger image in favor of saving time by not installing python. So my (potentially opinionated) solution would be to just replace
# build stage
FROM node:lts-alpine as build-stage
...
with
# build stage
FROM node:lts as build-stage
...
Solution 5:[5]
For me this only worked
Changing
FROM node:14-alpine
to
FROM node:14
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jordanvrtanoski |
Solution 2 | helvete |
Solution 3 | Y H |
Solution 4 | Stefan W |
Solution 5 | arun-r |