在Docker容器内部的路径中未找到Phantomjs

问题描述 投票:0回答:1

我正在尝试以Node 8作为基础映像在Docker容器中安装一堆依赖项。 Docker镜像在Ubuntu上构建并运行良好,但是当我在OS X上尝试时,出现此错误:

Error making request.
Error: getaddrinfo EAI_AGAIN github.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)

Please report this full log at https://github.com/Medium/phantomjs
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Dockerfile:

FROM node:8-alpine

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . /app
# ADD MONGOURL ENV HERE
EXPOSE 5000
CMD ["npm", "start"]

这里是我所有的依赖项:

"dependencies": {
    "body-parser": "^1.18.3",
    "compression": "^1.7.3",
    "cors": "^2.8.4",
    "express": "^4.16.4",
    "html-parse-stringify": "^1.0.3",
    "jsonwebtoken": "^8.3.0",
    "lodash": "^4.17.11",
    "mongoose": "^5.3.3",
    "morgan": "^1.9.1",
    "passport": "^0.4.0",
    "passport-facebook": "^2.1.1",
    "passport-google-oauth": "^1.0.0",
    "query-string": "^6.2.0",
    "request": "^2.88.0",
    "signalr-client": "0.0.19",     // 90% sure this is the one installs phantomjs
    "socket.io": "^2.1.1",
    "swagger-ui-express": "^4.0.1"
  },

为什么会这样?我以为docker应该解决这类问题。

node.js docker phantomjs
1个回答
0
投票

您可以在docker文件中添加一个步骤来安装phantomjs

FROM节点:8-高山

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . /app
EXPOSE 5000
CMD ["npm", "install", "phantom", "--save"]
CMD ["npm", "start"]

或在npm包中添加幻像依赖项。

您的phantomJS脚本将类似于:

const phantom = require('phantom');

(async function() {
    const instance = await phantom.create();
    const page = await instance.createPage();
    await page.on("onResourceRequested", function(requestData) {
        console.info('Requesting', requestData.url)
    });

    const status = await page.open('https://stackoverflow.com/');
    console.log(status);

    const content = await page.property('content');
    console.log(content);

    await instance.exit();
}());
© www.soinside.com 2019 - 2024. All rights reserved.