【问题标题】:Docker - build fails with operating system is not supported and The command '/bin/sh -c npm install' returned a non-zero codeDocker - 构建失败,操作系统不支持,命令“/bin/sh -c npm install”返回非零代码
【发布时间】:2021-08-02 05:23:59
【问题描述】:

我尝试为客户端应用(nextjs 应用)构建映像,但构建始终失败。

这是 docker 文件:

FROM node:12.18.3
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/
COPY package-lock.json /app/
RUN npm install
COPY . /app
RUN npm build
# start app
CMD [ "npm", "start" ]

第一步失败并出现此错误:

Step 1/9 : FROM node:12.18.3
operating system is not supported

我关注了这个帖子 https://stackoverflow.com/a/51071057/9608006 ,将 experimental 设置更改为 true,它确实通过了失败的步骤。

但现在它在npm i 步骤上失败了

npm notice
The command '/bin/sh -c npm install' returned a non-zero code: 4294967295: failed to shutdown container: container c425947f7f17ed39ed51ac0a67231f78ba7239ad199c7df979b3b442969a0a57 encountered an error during hcsshim::System::waitBackground: failure in a Windows system call: The virtual machine or container with the specified identifier is not running. (0xc0370110): subsequent terminate failed container c425947f7f17ed39ed51ac0a67231f78ba7239ad199c7df979b3b442969a0a57 encountered an error during hcsshim::System::waitBackground: failure in a Windows system call: The virtual machine or container with the specified identifier is not running. (0xc0370110)

在此步骤开始时我也收到此警告:

Step 6/9 : RUN npm install
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (windows/amd64) and no specific platform was requested

我用windows 10, docker v20.10.5

有什么问题?

编辑 1 - 文件夹结构

以下是客户端应用程序的基础文件夹层

  • .下一个
  • .vercel
  • 组件
  • 枚举
  • 挂钩
  • node_modules
  • 公开
  • 商店
  • 样式
  • 实用工具
  • .dockerIgnore
  • .env.local
  • next.config.js
  • package.json
  • server.js

【问题讨论】:

  • 您的 Docker 桌面版是什么?另外,您的 WSL 版本是多少?

标签: node.js docker npm next.js


【解决方案1】:

如果您使用的是 docker desktop.. 只需将 windows 容器的 docker desktop 选项默认更改为 linux 容器,然后再次运行您的 dockerfile。

【讨论】:

    【解决方案2】:

    您正在尝试在 Windows 下构建基于 Linux 的映像。 带有标签版本 12 的 nodejs 的多架构图像似乎存在问题。

    在您尝试过的帖子下尝试答案: 单击托盘中的 docker 图标并切换到 Linux 容器。

    https://stackoverflow.com/a/57548944/3040844

    【讨论】:

      【解决方案3】:

      根据你的 dockerfile

      FROM node:12.18.3
      WORKDIR /app
      ENV PATH /app/node_modules/.bin:$PATH
      COPY package.json /app/
      COPY package-lock.json /app/
      RUN npm install
      COPY . /app
      RUN npm build
      # start app
      CMD [ "npm", "start" ]
      

      你错过了正确的图像FROM node:12.18.3 这样做的正确方法FROM node:alpine3.12FROM ubuntu:18.04

      来自FROM directive is probably the most crucial amongst all others for Dockerfiles. It defines the base image to use to start the build process. It can be any image, including the ones you have created previously. If a FROM image is not found on the host, Docker will try to find it (and download) from the Docker Hub or other container repository. It needs to be the first command declared inside a Dockerfile

      带有节点映像的最简单 Dockerfile

      FROM node:alpine3.12 
      WORKDIR /usr/src/app
      COPY package*.json ./
      RUN npm install
      COPY ..
      RUN npm run build
      EXPOSE 3000
      CMD npm run start
      

      【讨论】:

        【解决方案4】:

        我认为这个问题与你的基础镜像有关,我在我身边使用了这个 Dockerfile 的 nextjs 应用程序,它工作正常:

        # Dockerfile
        
        # base image
        FROM node:alpine
        
        # create & set working directory
        RUN mkdir -p /app
        WORKDIR /app
        
        # copy source files
        COPY . /app
        
        # install dependencies
        RUN npm install
        
        # start app
        RUN npm run build
        EXPOSE 3000
        CMD npm run start
        
        

        希望能帮助您解决问题。

        【讨论】:

        • 我复制/粘贴这个 docker 文件而不是我的。它在第二步失败并出现类似错误:“第 2/8 步:运行 mkdir -p /app ---> [警告] 请求的图像平台 (linux/amd64) 与检测到的主机平台 (windows/amd64) 不匹配并且没有请求特定平台--->在cd4ceeb43c5c中运行命令'/bin/sh -c mkdir -p /app'返回非零代码:4294967295:“
        • 你能分享你的项目结构吗?
        • 我在第一次编辑中添加了它。如果还不够,请告诉我。谢谢你的帮助
        • 不客气,如果这个问题没有解决,请告诉我
        • 是的,它仍然没有解决。复制粘贴您的 dockerfile 后,我在第二步收到此错误:在 cd4ceeb43c5c 中运行命令“/bin/sh -c mkdir -p /app”返回非零代码:4294967295
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-02
        • 2021-03-19
        • 1970-01-01
        • 1970-01-01
        • 2019-10-09
        • 2019-06-12
        相关资源
        最近更新 更多