【问题标题】:Why docker is not able to build image out of Dockerfile ? Is it m1 chip issue?为什么 docker 无法从 Dockerfile 构建镜像?是m1芯片问题吗?
【发布时间】:2022-11-19 01:08:48
【问题描述】:

请分享可能的解决方案。 我正在尝试从 Dockerfile 构建 docker 镜像,但它需要无限的时间才能完成,它卡在了最后一步。

我在 imac m1 芯片上运行。 似乎是 m1 芯片的问题。

我已经使用 npx create-react-app react-app 创建了 react 项目。 我附上了下面的代码/

包.json

{
  "name": "react-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Dockerfile.dev

FROM node:alpine

WORKDIR /app

COPY package.json .

RUN npm install 

COPY . . 

RUN ["npm", "run", "start"]

docker-compose.yml

version: 'version'
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - 3000:3000
    volumes:
      - /app/node_modules
      - .:/app

【问题讨论】:

  • 除了主机的node_modules 目录之外,您是否有.dockerignore 文件? volumes: 块将导致 Docker 忽略此更改的影响;删除此块会有所作为吗?

标签: node.js reactjs docker


【解决方案1】:

运行[“npm”,“运行”,“开始”]

改为

CMD ["npm", "运行",

【讨论】:

  • 所以问题(它似乎“挂起”的原因)是您的 Dockerfile 有“RUN”(而不是“CMD”),对吗?建议:请Edit回复并复制/粘贴完整、更正的 Dockerfile,以及一些解释。