简体   繁体   English

Macbook m1 node.js docker 镜像构建失败

[英]Macbook m1 node js docker image build failed

This is message:这是消息: 在此处输入图像描述

What's wrong?怎么了? I should wait for the production docker?我应该等待生产 docker 吗?

This is docker config:这是 docker 配置:

# 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

Try running it with linux/amd64.尝试使用 linux/amd64 运行它。

In your docker config change:在您的 docker 配置更改中:

FROM node:lts-alpine as build-stage

to

FROM --platform=linux/amd64 node:lts-alpine as build-stage

For me this only worked对我来说这只管用

Changing改变

FROM node:14-alpine

to

FROM node:14

For me the solution of YH helps to add --platform=linux/amd64 in the FROM statement.对我来说,YH 的解决方案有助于在FROM语句中添加--platform=linux/amd64

But if you don't want to change your Dockerfile , you can also set DOCKER_DEFAULT_PLATFORM before building the docker image:但是如果你不想改变你的Dockerfile ,你也可以在构建 docker 图像之前设置DOCKER_DEFAULT_PLATFORM

export DOCKER_DEFAULT_PLATFORM=linux/amd64导出 DOCKER_DEFAULT_PLATFORM=linux/amd64

You need to install python as part of your build process.您需要在构建过程中安装 python。 For more details how to install python check here有关如何安装 python 的更多详细信息,请查看此处

# 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

You need python with make g++ to build your dependencies.您需要 python 和 make g++ 来构建您的依赖项。

FROM node:14-alpine as frontbuild FROM node:14-alpine 作为前端构建
#RUN apk add --no-cache python2 make g++ WORKDIR /tmp #RUN apk add --no-cache python2 make g++ WORKDIR /tmp

COPY./front/package.json. COPY./front/package.json。

RUN apk add --update --no-cache python2 make gcc libsass g++ RUN apk add --update --no-cache python2 make gcc libsass g++

RUN npm install --no-optional --only-production运行 npm 安装 --no-optional --only-production

COPY front /tmp复制前面/tmp

ARG VUE_APP_BASE_URL ENV VUE_APP_BASE_URL $VUE_APP_BASE_URL ENV NODE_ENV production ARG VUE_APP_BASE_URL ENV VUE_APP_BASE_URL $VUE_APP_BASE_URL ENV NODE_ENV 生产

RUN npm run build运行 npm 运行构建

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.那么,您需要 python。这里已经提供的答案将为您提供,极简主义者可能正在寻找类似的东西。

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我个人接受了一个更大的图像的开销,而不是安装 python 来节省时间。所以我的(可能是自以为是的)解决方案就是更换

# build stage
FROM node:lts-alpine as build-stage
...

with

# build stage
FROM node:lts as build-stage
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM