skip to Main Content

I’m new to Docker, and I’ve wanted try Dockerizing my node app.

I’ve tried following the directions on nodejs.org, but I’ve been getting errors on npm install.

Here is my Dockerfile:

# Use the latest 'node' official version
FROM node:current

# Set working directory to /usr/src/app
WORKDIR /usr/src/app

# Copy package.json, package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy all remaining files from the current directory
  # Note: 'node_modules' will not be overwritten because of .dockerignore
  # See: .dockerignore for the full list of ignored files
COPY . .

EXPOSE 3031

# Start the container using the server:watch command
CMD ["npm", "start"]

Here are the errors I’ve been receiving:

server$ docker build -t test .
Sending build context to Docker daemon  1.716MB
Step 1/8 : FROM node:current
 ---> b6f455933a97
Step 2/8 : WORKDIR /usr/src/app
 ---> Running in fbc7ef703e8f
Removing intermediate container fbc7ef703e8f
 ---> 18682f683fa1
Step 3/8 : COPY package*.json ./
 ---> 6f8ab073929f
Step 4/8 : RUN npm install
 ---> Running in 3105e1f65514
npm WARN tarball tarball data for @babel/[email protected] (sha512-0fKu/QqildpXmPVaRBoXOlyBb3MC+J0A66x97qEfLOMkn3u6nfY5esWogQwi/K0BjASYy4DbnsEWnpNL6qT5Mw==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha512-9nLya8GBtlFmmFMW7oXXwoXS1NkrccqTqAtwXzdPV9e2mqSEvCki6iHL/Fbzi5oqbugshzgGPk7KBb2qNP1DSA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha512-g0n4nH1ONGvqYo1v72uSWvF/MRNnnq1LzmSzXb/6EPF3LFb51akOhgG3K2+aETAsJx90/Q5eFNTntu4vBCwyQQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @babel/[email protected] (sha512-0fKu/QqildpXmPVaRBoXOlyBb3MC+J0A66x97qEfLOMkn3u6nfY5esWogQwi/K0BjASYy4DbnsEWnpNL6qT5Mw==) seems to be corrupted. Trying one more time.
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/@graphql-toolkit/schema-merging-eb6c200d/index.esm.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/@graphql-toolkit/core-0eb20c1b/index.esm.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/@types/node-66ad0ba4/https.d.ts'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/@graphql-toolkit/schema-merging-05667067/index.esm.js'
...
...
...
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/apollo-language-server-f6cf3e14/lib/engine/GraphQLDataSource.d.ts'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/apollo-language-server-f6cf3e14/lib/graphqlTypes.d.ts'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/serverless-146aad15/lib/plugins/create/templates/aws-clojure-gradle/gradlew'
npm WARN [email protected] No repository field.

npm ERR! Maximum call stack size exceeded
npm WARN tarball tarball data for [email protected] (sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=) seems to be corrupted. Trying one more time.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-02-10T10_05_40_789Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1

Additional information:

  • I am on Ubuntu 18.04
  • npm install always works on my local machine (outside of docker). It only seems to break on Docker.
  • Sometimes, the error ends with npm ERR! code EINTEGRITY.
  • Sometimes, docker indefinitely hangs after the first few npm WARN.
  • At the time of posting this question, I am using the latest LTS from nvm ls-remote (12.15.0). I have similarly tried downgrading to node 10 for both local and docker, with no success.

Please help.

Edit:
An example of the npm ERR! code EINTEGRITY error that I recieve.

npm WARN tar ENOENT: no such file or directory, open '/home/node/node_modules/.staging/@storybook/core-bb4e5c86/dll/storybook_ui-manifest.json'
npm WARN [email protected] No repository field.

npm ERR! code EINTEGRITY
npm ERR! Verification failed while extracting [email protected]:
npm ERR! Verification failed while extracting [email protected]:
npm ERR! sha512-jJfE/DW6tIK1Ek8nCfNFqt8Wb3nzMoAbocBF6/Icgg1ZFSBpObdnwVY2jQj6qUqzhx5jc71fpvBWyLGO7Xl+nQ== integrity checksum failed when using sha512: wanted sha512-jJfE/DW6tIK1Ek8nCfNFqt8Wb3nzMoAbocBF6/Icgg1ZFSBpObdnwVY2jQj6qUqzhx5jc71fpvBWyLGO7Xl+nQ== but got sha512-jbNiuTRS00nR58EcP7CCq2ld+M2yyKOEkKI0NwbUVCPecBmMiR8MFA7D7h/qKBzL+7DnmbZaNdPQr7DxIMGyoQ==. (69097 bytes)

Edit#2
An example of the output when I npm install after removing package-lock.json (hangs indefinitely at the end).

$ npm install
npm WARN deprecated [email protected]: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.
npm WARN deprecated [email protected]: The 'apollo-codegen' command has been replaced with the more-powerful 'apollo' CLI. Switch to 'apollo' to ensure future updates and visit https://npm.im/apollo#code-generation for more information.
npm WARN deprecated [email protected]: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated @types/[email protected]: This is a stub types definition. get-port provides its own type definitions, so you do not need this installed.
npm WARN deprecated [email protected]: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header).  This notice will go away with v5.0.2+ once it is released.
npm WARN deprecated @types/[email protected]: This is a stub types definition. vfile-message provides its own type definitions, so you do not need this installed.
npm WARN deprecated [email protected]: use String.prototype.padStart()
npm WARN tarball tarball data for validator@^12.2.0 (sha512-jJfE/DW6tIK1Ek8nCfNFqt8Wb3nzMoAbocBF6/Icgg1ZFSBpObdnwVY2jQj6qUqzhx5jc71fpvBWyLGO7Xl+nQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for typescript@^3.7.5 (sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for yargs@^15.0.0 (sha512-T39FNN1b6hCW4SOIk1XyTOWxtXdcen0t+XYrysQmChzSipvhBO8Bj0nK1ozAasdk24dNWuMZvr4k24nz+8HHLg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for web-resource-inliner@^4.3.3 (sha512-agVAgRhOOi4GVlvKK34oM23tDgH8390HfLnZY2HZl8OFBwKNvUJkH7t89AT2iluQP8w9VHAAKX6Z8EN7/9tqKA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for refractor@^2.4.1 (sha512-Xh9o7hQiQlDbxo5/XkOX6H+x/q8rmlmZKr97Ie1Q8ZM32IRRd3B/UxuA/yXDW79DBSXGWxm2yRTbcTVmAciJRw==) seems to be corrupted. Trying one more time.
[            ......] | extract:@types/history: sill extract @types/history@* extracted to /home/node/node_modules/.staging/@types/history-677b6da5 (5080ms)

Edit#3
Pasting my package.json here (excluding scripts, description and author). There is no custom npm install or postinstall script.

{
    "name": "server",
    "version": "0.0.2",
    "main": "handler.js",
    "dependencies": {
        "@koa/router": "^8.0.7",
        "@types/aws-lambda": "^8.10.40",
        "@types/base64-url": "^2.2.0",
        "@types/bcryptjs": "^2.4.2",
        "@types/graphql-depth-limit": "^1.1.2",
        "@types/jsonwebtoken": "^8.3.7",
        "@types/koa": "^2.11.0",
        "@types/koa-bodyparser": "^4.3.0",
        "@types/koa-logger": "^3.1.1",
        "@types/koa-passport": "^4.0.2",
        "@types/koa__router": "^8.0.2",
        "@types/lodash": "^4.14.149",
        "@types/mongodb": "^3.3.15",
        "@types/mongoose": "^5.7.0",
        "@types/node": "^13.7.0",
        "@types/nodemailer": "^6.4.0",
        "@types/object-hash": "^1.3.1",
        "@types/passport": "^1.0.2",
        "@types/passport-local": "^1.0.33",
        "@types/react": "^16.9.19",
        "@types/react-dom": "^16.9.5",
        "@types/redis": "^2.8.14",
        "@types/validator": "^12.0.1",
        "apollo-server-cache-redis": "^1.1.5",
        "apollo-server-koa": "^2.10.0",
        "base64-url": "^2.3.3",
        "bcryptjs": "^2.4.3",
        "can-error": "^0.2.0",
        "classnames": "^2.2.6",
        "dataloader": "^2.0.0",
        "dotenv": "^8.2.0",
        "graphql": "^14.6.0",
        "graphql-depth-limit": "^1.1.0",
        "graphql-middleware": "^4.0.2",
        "graphql-query-complexity": "^0.4.1",
        "graphql-rate-limit": "^2.0.1",
        "graphql-scalars": "^1.0.6",
        "graphql-shield": "^7.0.10",
        "graphql-tools": "^4.0.6",
        "http-status-codes": "^1.4.0",
        "iexcloud_api_wrapper": "^1.1.5",
        "jsonschema": "^1.2.5",
        "jsonwebtoken": "^8.5.1",
        "juice": "^6.0.0",
        "koa": "^2.11.0",
        "koa-bodyparser": "^4.2.1",
        "koa-logger": "^3.2.1",
        "koa-passport": "^4.1.3",
        "lodash": "^4.17.15",
        "moment": "^2.24.0",
        "mongodb-memory-server": "^6.2.4",
        "mongoose": "^5.8.11",
        "nodemailer": "^6.4.2",
        "object-hash": "^2.0.1",
        "passport-local": "^1.0.0",
        "react": "^16.12.0",
        "react-dom": "^16.12.0",
        "react-jss": "^10.0.4",
        "redis": "^2.8.0",
        "saslprep": "^1.0.3",
        "serverless-http": "^2.3.1",
        "source-map-support": "^0.5.16",
        "typescript": "^3.7.5",
        "validator": "^12.2.0",
        "winston": "^3.2.1"
    },
    "devDependencies": {
        "@babel/core": "^7.8.4",
        "@babel/preset-env": "^7.8.4",
        "@babel/preset-typescript": "^7.8.3",
        "@geut/chan": "^2.1.1",
        "@graphql-codegen/cli": "^1.12.2",
        "@graphql-codegen/typescript": "^1.12.2",
        "@storybook/addon-docs": "^5.3.12",
        "@storybook/addon-knobs": "^5.3.12",
        "@storybook/addon-storyshots": "^5.3.12",
        "@storybook/addon-viewport": "^5.3.12",
        "@storybook/addons": "^5.3.12",
        "@storybook/components": "^5.3.12",
        "@storybook/preset-create-react-app": "^1.5.2",
        "@storybook/react": "^5.3.12",
        "@storybook/theming": "^5.3.12",
        "@types/faker": "^4.1.9",
        "@types/jest": "^25.1.2",
        "@typescript-eslint/eslint-plugin": "^2.19.0",
        "@typescript-eslint/eslint-plugin-tslint": "^2.19.0",
        "@typescript-eslint/parser": "^2.19.0",
        "audit-ci": "^2.4.2",
        "aws-lambda": "^1.0.5",
        "babel-loader": "^8.0.6",
        "babel-plugin-require-context-hook": "^1.0.0",
        "customize-cra": "^0.9.1",
        "eslint": "^6.8.0",
        "eslint-config-prettier": "^6.10.0",
        "eslint-config-react": "^1.1.7",
        "eslint-config-standard": "^14.1.0",
        "eslint-import-resolver-alias": "^1.1.2",
        "eslint-plugin-import": "^2.20.1",
        "eslint-plugin-mdx": "^1.6.8",
        "eslint-plugin-node": "^11.0.0",
        "eslint-plugin-prefer-arrow": "^1.1.7",
        "eslint-plugin-prettier": "^3.1.2",
        "eslint-plugin-promise": "^4.2.1",
        "eslint-plugin-react": "^7.18.3",
        "eslint-plugin-standard": "^4.0.1",
        "faker": "^4.1.0",
        "jest": "^25.1.0",
        "jest-transform-graphql": "^2.1.0",
        "node-loader": "^0.6.0",
        "nodemon": "^2.0.2",
        "npm-run-all": "^4.1.5",
        "prettier": "^1.19.1",
        "react-scripts": "^3.3.1",
        "serverless": "^1.63.0",
        "serverless-dotenv-plugin": "^2.3.1",
        "serverless-offline": "^5.12.1",
        "serverless-webpack": "^5.2.0",
        "ts-loader": "^6.2.1",
        "tsconfig-paths-jest": "0.0.1",
        "tslint": "^6.0.0",
        "webpack": "^4.41.5",
        "webpack-cli": "^3.3.10",
        "webpack-graphql-loader": "^1.0.2"
    }
}

2

Answers


  1. I used to get this error due to low or intermittent internet bandwidth.

    Login or Signup to reply.
  2. Remove package-lock.json. If you have npm-shrinkwrap.json and node_modules then remove these as well and then finally remove the caching if any.

    rm -rf package-lock.json npm-shrinkwrap.json node_modules  
    npm cache clean --force
    

    Now build a fresh docker container and the issue shold be resolved. Further add package-lock.json as a fresh file.

    npm i --package-lock-only
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search