无法在Docker中正确安装软件包

时间:2020-09-28 14:46:53

标签: node.js docker npm

我能够使用npm安装所有软件包,但是两天前我收到了此错误。

Step 8/12 : RUN npm install
 ---> Running in aedc04c5281e

> sharp@0.25.4 install /home/project/website/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-linuxmusl-x64.tar.gz

> cwebp-bin@5.1.0 postinstall /home/project/website/node_modules/cwebp-bin
> node lib/install.js

  ⚠ spawn /home/project/website/node_modules/cwebp-bin/vendor/cwebp ENOENT
  ⚠ cwebp pre-build test failed
  ℹ compiling from source
...

这是我的docker文件

FROM node:12-alpine

RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm

RUN mkdir -p /home/project/website/node_modules && chown -R node:node /home/project/website

WORKDIR /home/project/website

COPY /package*.json ./

USER node

RUN npm cache verify

RUN npm install

COPY --chown=node:node . .

RUN chmod +x wait-for.sh

RUN chmod -R 0755 /home/project/website/src/views/

EXPOSE 8080

大楼建成后,我会在日志中得到

internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module '/home/project/website/node_modules/.bin/nodemon'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

在我运行以下cmd之后 docker-compose run website sh -c "npm list --depth=0" 我明白了

+-- UNMET DEPENDENCY bcryptjs@2.4.3
+-- UNMET DEPENDENCY compression@1.7.4
| +-- accepts@1.3.7
| +-- bytes@3.0.0
| +-- compressible@2.0.18
| +-- debug@2.6.9
| +-- on-headers@1.0.2
| +-- safe-buffer@5.1.2
| `-- vary@1.1.2
+-- UNMET DEPENDENCY cors@2.8.5
| +-- object-assign@4.1.1
| `-- vary@1.1.2
+-- UNMET DEPENDENCY dateformat@3.0.3
+-- UNMET DEPENDENCY dotenv@8.2.0
+-- UNMET DEPENDENCY ejs@3.1.5
| `-- jake@10.8.2
+-- UNMET DEPENDENCY express@4.17.1
...

我的包裹是

{
  "name": "website",
  "version": "0.0.0",
  "main": "app.js",
  "scripts": {
    "start": "nodemon src/app.js"
  },
  "author": "Noah Lc",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "dateformat": "^3.0.3",
    "dotenv": "^8.2.0",
    "ejs": "^3.1.3",
    "express": "^4.17.1",
    "fs": "0.0.1-security",
    "helmet": "^4.1.1",
    "image-size": "^0.8.3",
    "imagemin": "^7.0.1",
    "imagemin-mozjpeg": "^9.0.0",
    "imagemin-webp": "^6.0.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.7.7",
    "multer": "^1.4.2",
    "nodemailer": "^6.4.11",
    "nodemon": "^2.0.3",
    "sharp": "^0.25.4",
    "sitemap": "^6.2.0",
    "slugify": "^1.4.0",
    "superagent": "^5.2.2",
    "validator": "^12.0.0",
    "winston": "^3.3.3"
  },
  "devDependencies": {}
}

是否有任何干净的方法可以跳过插件本身中那些浸入的构建前和构建后步骤,从而避免在容器化环境中出现任何问题?

0 个答案:

没有答案