Docker build卡在npm run build步骤

kse8i1jr  于 2023-06-29  发布在  Docker
关注(0)|答案(2)|浏览(182)

我试图创建一个docker镜像,但它在“npm run build”步骤中卡住了。我可以看到构建成功完成的消息,但它没有继续进行下一步。
在docker文件下面。我正在使用node:16.13.1作为基本映像

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
COPY .npmrc ./
RUN npm install node-sass@latest
RUN npm install core-js@2.5.7
RUN npm install
COPY . /usr/src/app
# build web app
RUN npm run build
EXPOSE 8080
RUN chmod +x /usr/src/app/setup.sh
CMD ["/usr/src/app/setup.sh"]

在以下步骤

后不继续
Package.json文件

{
  "name": "full-kyc",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "format": "prettier --write \"**/*.{js,vue,html,json,md}\" && prettier-stylelint --write --quiet '**/*.{css,scss,vue}'",
    "build:dev": "vue-cli-service build --mode development --watch",
    "start:dev": "NODE_ENV=development nodemon bin/www | bunyan",
    "start:prod": "node bin/www | bunyan"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,vue,html,json,md}": [
      "prettier --write",
      "git add"
    ],
    "*.{css,scss,vue}": [
      "prettier-stylelint --write --quiet",
      "git add"
    ]
  },
  "dependencies": {
    "@vue/babel-preset-app": "^4.5.15",
    "axios": "^0.21.4",
    "body-parser": "1.18.3",
    "btoa": "^1.2.1",
    "bunyan": "1.8.12",
    "cookie-parser": "1.4.3",
    "crypto": "^1.0.1",
    "express": "4.16.3",
    "express-http-proxy": "1.4.0",
    "raven-js": "^3.27.2",
    "vue": "2.5.17",
    "vue-router": "3.0.1",
    "vuex": "3.0.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.5.15",
    "@vue/cli-plugin-eslint": "3.0.1",
    "@vue/cli-service": "3.0.1",
    "babel-eslint": "^10.1.0",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^6.15.0",
    "eslint-loader": "^2.2.1",
    "eslint-plugin-prettier": "^3.4.1",
    "eslint-plugin-vue": "^5.2.3",
    "husky": "^3.1.0",
    "lint-staged": "^9.5.0",
    "node-sass": "^4.14.1",
    "nodemon": "1.18.4",
    "prettier": "^1.19.1",
    "prettier-stylelint": "^0.4.2",
    "sass-loader": "7.0.1",
    "stylelint-config-recommended": "^2.2.0",
    "vue-template-compiler": "2.5.17",
    "vue-smooth-picker": "file:vue-smooth-picker",
    "webpack-bundle-analyzer": "^4.5.0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true,
      "es6": true,
      "browser": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended",
      "prettier/vue",
      "plugin:prettier/recommended"
    ],
    "rules": {
      "vue/component-name-in-template-casing": [
        "error",
        "PascalCase"
      ]
    },
    "globals": {
      "axios": "readonly"
    },
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "stylelint": {
    "rules": {
      "no-descending-specificity": null
    },
    "extends": "stylelint-config-recommended"
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}
sc4hvdpw

sc4hvdpw1#

变化

RUN npm run build

CMD ["npm", "run", "build"]
6l7fqoea

6l7fqoea2#

我遇到了同样的问题。对我来说,解决方案是为Docker引擎分配更多资源。
我使用的是Intel MacBook Pro(6核i7,16 GB RAM),我使用Colima作为Docker引擎。
根据Colima文档,默认的VM分配是2个CPU,2GiB内存和60 GiB存储。我使用Colima CLI增加了这一点,如下所示:

colima start --cpu 4 --memory 10 --disk 80

当使用默认分配时,我在RUN npm run build命令花费3200多秒后杀死了docker构建。在我重新启动Colima并分配了更多的cpu/mem之后,这一步在95秒内成功完成。

相关问题