Macbook m1 node js docker image build failed
Asked Answered
G

6

6

This is message: enter image description here

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
Guddle answered 11/3, 2021 at 17:55 Comment(1)
Seems like one of the dependencies require python to be inside the docker imageGianina
R
11

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

Rasputin answered 2/3, 2022 at 22:16 Comment(0)
O
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
Oireachtas answered 24/11, 2021 at 11:5 Comment(0)
T
2

For me the solution of Y H helps to add --platform=linux/amd64 in the FROM statement.

But if you don't want to change your Dockerfile, you can also set DOCKER_DEFAULT_PLATFORM before building the docker image:

export DOCKER_DEFAULT_PLATFORM=linux/amd64

Tourer answered 6/10, 2022 at 16:44 Comment(0)
T
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
Transistorize answered 11/3, 2021 at 18:33 Comment(3)
same loop, check if the binary/library/package is missing, and if so add to the Dockerfile. If you ware not tracking the dependancies properly, you will need to repeat this cycle several times until you find all the things that you are missing.Transistorize
I recently bought a MacBook m1, in Linux os docker file was ok and no problem.Guddle
M1 is ARM64, some libraries/packages are still not available for M1, but it's not the case with node-gyp, it's most probably a problem with installation of the C/C++ build environment. Add apk add alpine-sdk to the Dockerfile and check agin.Transistorize
L
1

For me this only worked

Changing

FROM node:14-alpine

to

FROM node:14
Lydon answered 8/5, 2022 at 4:37 Comment(0)
D
0

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
...
Downtown answered 16/2, 2022 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.