在多平台linux/amd64、linux/arm64上构建react应用程序作为docker镜像失败

问题描述 投票:0回答:1

我目前有这个代码:

name: Push Backend as Docker Image

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v3

      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Build and push Docker image
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          push: true
          tags: user/docker-image:latest
          platforms: linux/amd64,linux/arm64 

当我在 Github 上操作时我得到了这个:

ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 1
Error: buildx call failed with: ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 1

之前我没有在yml文件中写入platform属性,像这样:

name: Push Backend as Docker Image

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v3

      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build and push Docker image
        uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
        with:
          context: .
          push: true
          tags: user/docker-image:latest

我认为错误可能来自我添加的平台属性,因为我上面发送的代码工作得很好。

错误日志:https://prnt.sc/gItIf-_R5HNY

Dockerfile:

# Use an official Node.js runtime as the base image
FROM node:16.15.1-alpine as builder

# Set the working directory in the container
WORKDIR /app

# Copy the package.json and package-lock.json files to the container
COPY package*.json ./

# Install project dependencies
RUN npm install


# Copy the rest of the application code to the container
COPY . .

# Generate the Prisma client
RUN npx prisma generate

# # Generate the Prisma client
# RUN npx prisma migrate deploy

# Expose the port on which your Node.js application will listen
EXPOSE 4500

# Set the command to run your Node.js application
CMD ["node", "index.js"]

这是因为ARM64和bcrypt的问题吗:

这是错误的一些日志

     > [linux/arm64 4/6] RUN npm install:
143.3 npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
143.3 npm ERR! node-pre-gyp ERR! System Linux 6.2.0-1018-azure
143.3 npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/app/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
143.3 npm ERR! node-pre-gyp ERR! cwd /app/node_modules/bcrypt
143.3 npm ERR! node-pre-gyp ERR! node -v v16.15.1
143.3 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.9
143.3 npm ERR! node-pre-gyp ERR! not ok
enter code here
docker github-actions arm64
1个回答
0
投票

问题出在库

bcrypt
上,解决方案是从package.json中删除bcrypt并安装
bcryptjs
,因为bcrypt在ARM64上有问题,我尝试使用bcryptjs工作得很好,没有遇到任何错误。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.