Docker build getting stuck at npm run build step
Asked Answered
R

2

5

I was trying to create a docker Image where it is getting stuck at the "npm run build" step. I could see the message as build completed successfully but it is not proceeding to the next step.

below the docker file. I m using node:16.13.1 as base Image

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
COPY .npmrc ./
RUN npm install node-sass@latest
RUN npm install [email protected]
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"]

Not proceeding after the below step,enter image description here

Package.json file

{
  "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"
  ]
}

Ratline answered 8/12, 2021 at 7:10 Comment(2)
can you share package.json file here ?Breeder
Added it in the questionRatline
D
1

I ran into this same issue. For me, the solution was allocating more resources to the docker engine.

I am on an Intel MacBook Pro (6-core i7, 16GB RAM) and I am using Colima as the docker engine.

According to the Colima docs, the default VM allocation is 2 CPUs, 2GiB memory and 60GiB storage. I increased this using the Colima CLI as follows:

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

When using the default allocation I killed the docker build after the RUN npm run build command was taking 3200+ seconds. After I restarted Colima with more cpu/mem allocation that step completed successfully in 95 seconds.

Downdraft answered 28/6, 2023 at 3:19 Comment(0)
W
-1

change

RUN npm run build

to

CMD ["npm", "run", "build"]
Wherewithal answered 3/6, 2022 at 23:2 Comment(2)
This will make building the application the only thing the container does, and it will immediately exit after doing the build. Usually you will in fact want to build it during the docker build phase, that is, with RUN, and use CMD to run or serve the application.Kudva
@david-maze that's exactly what we need from a build command. for running it we use docker runMonsour

© 2022 - 2024 — McMap. All rights reserved.